2016-10-01 4 views
2

私はベクター描画可能を使用しています。私は40dpのバックグラウンドと24dpのイメージでイメージを表示します。 私は今、このレイアウトを持っている:ベクトル描画可能なサイズのImageView

<ImageView 
      android:id="@+id/image" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:background="@drawable/circle" 
      android:src="@drawable/ic_image" 
      android:tint="@android:color/white" 
      tools:ignore="ContentDescription"/> 

問題は、画像を拡大縮小していることであり、すべてのベクトル描画可能で、私が持っている場合でも、40dpいっぱい:

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

描画可能円であります:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="oval"> 
    <solid 
     android:color="@color/colorAccent"/> 
    <size 
     android:width="40dp" 
     android:height="40dp"/> 
</shape> 

レイアウトを修正するにはどうすればよいですか?ベクトルをpngに変換する必要がありますか?

+1

デフォルトで 'ImageView'は' Drawable'を 'ScaleType.FIT_CENTER'でスケーリングし、他の値は' ImageView.ScaleType'を参照してください – pskink

+0

@pskinkありがとう、スケールセンターで解決しました – greywolf82

+0

良い: 2層(円とベクトル)の 'LayerDrawable'を' View#setBackground'に渡します。 'ImageView'は必要ありません。 – pskink

答えて

3

centerの値を持つandroid:scaleTypeを使用して問題を解決しました。

関連する問題