androidkotlinandroid-automotive

how to show images in high quality in android auto in a row


Below is the code I'm using, but it's causing the image to blur. I've tried both XML and PNG formats—XML appears blurry, while the PNG image looks pixelated and broken.

    private fun getIcon(type: String): CarIcon {
            val iconResId =
                when (type) {
                    "a" -> R.drawable.a
                    "b" -> R.drawable.b
                    "c" -> R.drawable.c
                    "d" -> R.drawable.d
                    "e" -> R.drawable.e
                    "f" -> R.drawable.f
                    else -> R.drawable.g
                }
   return CarIcon.Builder(IconCompat.createWithResource(carContext, iconResId)).build()
   }
    // calling the above function
    Row.Builder().setImage(getIcon(type))

Solution

  • The version of setImage you're using defaults to the IMAGE_TYPE_SMALL image type, which gets scaled to 88 x 88 dp.

    Instead, you could use the following:

    Row.Builder().setImage(getIcon(type), IMAGE_TYPE_LARGE)
    

    IMAGE_TYPE_LARGE will scale to 224 x 224 dp.