2

I've got a ConstraintLayout which I scale by using scaleX and scaleY, this works perfectly on most devices but I've noticed that ImageViews inside the ConstraintLayout looks very pixelated on certain phones (OnePlus running Android 9).

Samsung Galaxy S10, Android 9 with FHD resolution:

Samsung Galaxy S10, Android 9 with WHQL resolution:

The ImageView uses a vector drawable and we've set the following:

  • AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
  • vectorDrawables.useSupportLibrary = true

However the image is still pixelated on certain phones (OnePlus)

Any ideas why?

Edit

This is the drawable:

<vector
    android:height="24dp"
    android:viewportHeight="52"
    android:viewportWidth="52"
    android:width="24dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#00394D" android:fillType="evenOdd"
        android:pathData="M1.0024,26.342C0.8134,12.559 11.873,1.1907 25.6569,1.0018L26.0037,1C39.5995,1 50.8108,12.0613 50.9971,25.658C51.186,39.441 40.1256,50.8093 26.3417,50.9973L25.994,51C12.399,51 1.1878,39.9387 1.0024,26.342ZM25.7394,7.0155C20.6766,7.0856 15.9386,9.1268 12.3982,12.7657C8.8577,16.4046 6.946,21.1976 7.0152,26.2604C7.1562,36.5854 15.6707,44.9863 25.9957,44.9863L26.2592,44.9845C36.7271,44.8408 45.1271,36.2075 44.9843,25.7396C44.8423,15.4146 36.3279,7.0137 26.0037,7.0137L25.7394,7.0155Z"
        android:strokeColor="#00000000" android:strokeWidth="1"/>
    <path android:fillColor="#009DDB" android:fillType="evenOdd"
        android:pathData="M26.3287,12.2772C24.6911,12.2772 23.3593,13.6099 23.3593,15.2476L23.3593,28.2101C23.3593,28.4019 23.3795,28.5973 23.4171,28.791L23.4706,28.9811L23.5135,29.1222L23.5862,29.3456C23.6213,29.4297 23.6642,29.5086 23.7089,29.5857L23.7737,29.7048L23.8579,29.8564C23.97,30.0238 24.0962,30.1771 24.232,30.3129L29.5645,35.6464C30.1253,36.208 30.871,36.5164 31.6648,36.5164C32.4586,36.5164 33.2043,36.208 33.765,35.6464C34.9225,34.4889 34.9225,32.6042 33.765,31.4467L29.2982,26.9807L29.2982,15.2476C29.2982,13.6099 27.9664,12.2772 26.3287,12.2772"
        android:strokeColor="#00000000" android:strokeWidth="1"/>
</vector>

This is the ImageView:

<ImageView
    android:id="@+id/clock"
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/ic_clock"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • `android:layout_width` and `android:layout_height` try making it `wrap_content` and let vector adjust it self, and try changing vector size only – Abdul Kawee Apr 29 '19 at 07:08
  • add same File in drawable-xxxhdpi and drawable-xxhdpi – Ganesh Pokale Apr 29 '19 at 07:27
  • Does this answer your question? [Why isn't my vector drawable scaling as expected?](https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected) – Mahozad Oct 14 '20 at 08:51

1 Answers1

0

You can add android:scaleType="fitXY" to an ImageView

It might solve your problem

and also make sure your vector is not containing decimal value like this .2 or .4 it should be like 0.2 and 0.4 you can analyse it from code inspector

Any you even can change your vector width and height as you set 24dp because it is by default you can try like this it may help

<vector android:height="80dp" android:width="80dp"

Something like this

Arbaz Pirwani
  • 935
  • 7
  • 22