Why isn't my vector drawable scaling as expected?

后端 未结 8 1365
北恋
北恋 2020-11-28 20:18

I am attempting to use vector drawables in my Android app. From http://developer.android.com/training/material/drawables.html (emphasis mine):

In And

相关标签:
8条回答
  • 2020-11-28 20:43

    I solve my problem just change size of vector image. From the first it was resource like:

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:aapt="http://schemas.android.com/aapt"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="300"
        android:viewportWidth="300">
    

    And I've changed it to 150dp (size of ImageView in layout with this vector resource) like:

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:aapt="http://schemas.android.com/aapt"
        android:width="150dp"
        android:height="150dp"
        android:viewportHeight="300"
        android:viewportWidth="300">
    

    It's working for me.

    0 讨论(0)
  • 2020-11-28 20:47

    I try must of these ways but unfortunately, none of them worked. I try fitXY in ImageView, I try using app:srcCompat but cannot even use it. but I found a trick way:

    set the Drawable to background of your ImageView.

    But the point of this way is Views dimensions. if your ImageView has incorrect dimensions, drawable gets Stretch. you must control it in pre-lollipop versions or Use some Views PercentRelativeLayout.

    Hope it's helpful.

    0 讨论(0)
提交回复
热议问题