私は、このアイコンを持っています。最も簡単な方法は、プログラム
Drawable myIcon = getResources().getDrawable(R.drawable.icon);
私は、プログラム上にテキストを入力する必要があります(ファイル拡張子)。
これは私の希望する結果です:。
私は、これはあなたを助けるmethod.will使用し、任意のファイル拡張子
私は、このアイコンを持っています。最も簡単な方法は、プログラム
Drawable myIcon = getResources().getDrawable(R.drawable.icon);
私は、プログラム上にテキストを入力する必要があります(ファイル拡張子)。
これは私の希望する結果です:。
私は、これはあなたを助けるmethod.will使用し、任意のファイル拡張子
public BitmapDrawable writeOnDrawable(int drawableId, String text){
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
Canvas canvas = new Canvas(bm);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
return new BitmapDrawable(bm);
}
を受け取ることができますので、私はいくつかの静的なアイコンを作成することはできません。
に変換したくありません。それは私が必要とするものに似ています –
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/folder"
android:src="@drawable/image_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:textColor="@color/green"
android:textStyle="bold"
android:id="@+id/text"
android:text="10"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
この画像のどこかに印刷するつもりがなく、単に画面に表示する必要がある場合は、おそらく最も簡単な方法はimg
の中央にtext
を印刷することです。
あなたは、これはおそらく最も簡単な解決策であり、それは、IMGのサイズに基づいて、画像の中心にテキストを揃えますRelativeLayout
<RelativeLayout> // Only works inside a RelativeLayout
<ImageView
android:id="@+id/myImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myImageSouce" />
<TextView
android:id="@+id/myImageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/myImage"
android:layout_alignTop="@+id/myImage"
android:layout_alignRight="@+id/myImage"
android:layout_alignBottom="@+id/myImage"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
</RelativeLayout>
を使用することによってそれを行うことができます。
それは簡単です、 'RelativeLayout'の中に' ImageView'と 'TextView'を取ります。 TextViewの重力をLayoutの中心に設定します。 –
これと、RelativeLayoutを使用するその他の回答はDrawableを受け取る必要があるため私には適していません。レイアウトをBitmap/Drawable –