3

我下面ImageButtonVectorDrawable上的ImageButton是醜陋

<ImageButton xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fireButton" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/ic_whatshot_48px" 
    android:tint="@color/accent" 
    style="?android:attr/borderlessButtonStyle" 
    android:scaleType="fitCenter" 
    android:onClick="fire" /> 

ic_whatshot_48pxVectorDrawable

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="48dp" 
    android:height="48dp" 
    android:viewportWidth="48" 
    android:viewportHeight="48"> 

    <path 
     android:fillColor="#000000" 
     android:pathData="M27 1.34s1.48 5.3 1.48 9.6c0 4.12-2.7 7.47-6.83 
7.47s-7.25-3.34-7.25-7.47l.05-.72C10.43 15.03 8 21.23 8 28c0 8.84 7.16 16 16 
16s16-7.16 16-16c0-10.79-5.19-20.41-13-26.66zM23.42 38c-3.56 
0-6.45-2.81-6.45-6.28 0-3.25 2.09-5.53 5.63-6.24s7.2-2.41 9.23-5.15c.78 2.58 
1.19 5.3 1.19 8.07 0 5.29-4.3 9.6-9.6 9.6z" /> 
</vector> 

但對圖像進行縮放,並且所迷離和醜陋。

Ugly VectorDrawable screenshot

這是爲什麼?這是VECTORDrawable,它應該很好,很順利。

+0

我們可以看到'VectorDrawable'代碼嗎? – 2015-02-11 17:40:21

+1

也許這是因爲您的SVG是48x48px? – Zielony 2015-02-11 17:43:14

+0

是的,你可以。我將它添加到問題中。我知道我可以改變'width','height' anbd視口,但我不知道應用程序在哪個屏幕上運行,所以我不能使用確切的數字。我想要Android來做到這一點。 :) – Pitel 2015-02-11 17:43:33

回答

1

也許現在回答這個問題爲時已晚,但也可能有其他人有同樣的問題。

問題是由於矢量定義中的寬度和高度。您將其設置爲較低的值將其設置爲較高的值,然後完成。

如果你想使用它的多屏幕尺寸,那麼你需要做這樣的事情:

<vector ... 
     android:width="@dimen/vector_size" 
     android:height="@dimen/vector_size" 
     .../> 

然後在res /值定義的:

<resources> 
    <dimen name="vector_size">24dp</dimen> 
</resources> 

欲瞭解更多信息爲什麼你需要給矢量的寬度和高度,請閱讀:

Understanding Android's VectorDrawable properties

+0

這是不正確的。在ImageView中的srcCompat。你正在談論默認大小。 – cesards 2016-10-12 11:21:59