2016-03-29 15 views
1

私は自分のプロジェクトに、多くのスケール(mdpiは32px、hdpiは48px、xhdpiは64px、xxhdpiは96px、Androidスタジオによって自動的に作成されます)のPNGアイコンのリストを持っています。 1つのアクティビティで、このアイコンを2つの異なるサイズで表示したい。大きな画像に描画可能な解像度を設定する

大きな問題(私が実際にレイアウトの幅と高さを定義する唯一のもの)は、より良いものの代わりにdrawableの低解像度バージョンを使用するということです。ここで

は私のXMLコードです:

<!-- small icon --> 
<ImageView 
    android:layout_weight="1" 
    android:layout_width="1dp" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_icon_like" /> 
<!-- ... --> 
<!-- big icon --> 
<ImageView 
    android:layout_weight="1" 
    android:src="@drawable/ic_icon_like" 
    android:layout_width="90dp" 
    android:layout_height="90dp" /> 

そして、ここでは結果である。比較のためとして

Screenshot of the two ImageViews from the emulator

、ここではドロウアブルのPNGのxxhdpiバージョンがより明らかに優れ、です私が持っている大きなもの。

xxhdpi version of the Drawable

私は、Androidに新たなんだので、私は私が何か間違ったことをやっていると仮定し、私は何を理解することはできません。解像度ごとに高解像度の画像を定義する必要がありますか?表示される2つのバージョンにic_icon_likeic_icon_like_bigを提供する必要がありますか?

+0

より大きいイメージビューで 'android:scaleType =" fitXY "'を使ってみてください。 – Omkar

+0

それを試してみると、それはちょうど私に同じぼやけた親指を与える、少し歪んだ。 –

+0

実際、resフォルダに大きなサイズのドロワブルを定義しないでください(250xxxxddpiのようなもの)。 Android Studioで生成されるサイズは「アクションバーとタブアイコン」用ですが、これは私の場合ではありません。 –

答えて

1

私はSVG形式ですべてのアイコンを取得していたので、ついに、代わりにWebfontを使用しました。

サイジングとカラーリングはこれほど簡単です。

だから私は、私のプロジェクトで/app/assets/fonts/webfont.ttfファイルを追加して、このようなTextViewからIconView heritingを作成:

public class IconView extends TextView { 
    public IconView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     // here I trully use a cache, but remove it for a full example 
     this.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/webfont.ttf")); 
     // the following allows me to use a default color if no 'textColor' attribute is provided 
     int[] set = {android.R.attr.textColor}; 
     TypedArray attributes = context.obtainStyledAttributes(attrs, set); 
     ColorDrawable color = (ColorDrawable) attributes.getDrawable(0); 
     attributes.recycle();  
     if (color == null) { 
      this.setTextColor(MY_DEFAULT_COLOR); 
     } 
    } 
} 

また、私のように、私のwebfont内の各アイコンについてstrings.xmlの定数を追加しました:

<string name="icon_like">&#xe635;</string> 

そして、このような私のXMLアクティビティとフラグメントで全体を使用しました:

<com.mySociety.myProject.IconView android:text="@string/icon_like" /> 
関連する問題