1

小さなカレンダーの画像を撮り、日付と月を書きたいと思っています。これはリストビューで何度も表示されるので、最適な方法を模索中です。

以下はうまく機能します、より良い方法はありますか:

ImageView image = (ImageView) findViewById(R.id.imageView2);
try {
    // Load the png image into a bitmap
    Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.calendar_empty);
    // Have to copy the bitmap so it is mutable
    mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
    // Create a canvas from the bitmap to draw on
    Canvas canvas = new Canvas(mBitmap);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTextSize(12);
    paint.setAntiAlias(true);
    canvas.drawText("Sept", 11, 26, paint);
    paint.setTextSize(18);
    canvas.drawText("29", 14, 42, paint);
    // Display the results on the screen
    image.setImageDrawable(new BitmapDrawable(this.getResources(), mBitmap));
} catch (Exception e) {
    e.printStackTrace ();
}
4

1 に答える 1

2

ImageViewを取得し、これを可能にするレイアウトコンテナ(RelativeLayoutやFrameLayoutなど)内に、タイトルのオーバーレイとしてTextViewを配置してみませんか?

このように画像にタイトルを書くプロジェクトがいくつかありましたが、このアプローチに問題はありませんでした。

于 2012-04-15T18:04:51.187 に答える