I have an image display issue on API 21+, but everything works fine on lower devices and API 22+. I'm using Gradle Plugin 1.5, so my build.gradle
look like this:
// Gradle Plugin 1.5
android {
defaultConfig {
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Image View in XML:
<ImageView
android:id="@+id/landing_img_slide"
android:layout_width="225dp"
android:layout_height="225dp"
android:layout_centerHorizontal="true"
android:scaleType="centerCrop" />
Java Code :
ImageView iconView = (ImageView) itemView.findViewById(R.id.landing_img_slide);
iconView.setImageResource(R.drawable.laptopscreen);
Below Screenshots will shows ImageView
with VectorDrawable works fine with Pre-lollipop and Marshmallow but shows Blurry Image in Android 5.0.1
Android 4.4.4
Android 5.0.1
Android 6.0.1
This is to do with the scaleType in your ImageView which does inconsistent things at these different API levels when it comes to VectorDrawables.
There is one scaleType which seems to consistently give a sharp image when scaling: android:scaleType="fitXY"
but when using this you have to ensure that the ImageView has the same aspect ratio as the Vector Drawable (eg. if you use fitXY with a square VectorDrawable and a rectangular ImageView it will stretch the image out).
Alternatively you can change the size in the VectorDrawable itself by setting
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="225dp"
android:height="225dp"
.../>
By doing this there will be no scaling necessary in the ImageView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With