3

キャンバスを使用してテキストを描画しようとしています。どこでもチェックアウトしましたが、これらの例はかなり複雑で、キャンバスにテキストを描くことはできましたが、この写真のようには表示されません。

ここに画像の説明を入力

このコードを見つけて動作しています。上の画像のように書くだけです。

        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setTextSize(30);
        paint.setAntiAlias(true);

        canvas.drawText("There are 137 days, 9 hours 4 minutes and 36 seconds", 150,150, paint);
4

1 に答える 1

6

必要なフォントを取得して、アセット フォルダーに追加します。フォントファイル名が「pretty.otf」だとしましょう。次に、コードで行う必要があるのはそれだけです。

Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(30);
paint.setAntiAlias(true);

Context mContext = getContext();
Typeface myTypeface = Typeface.createFromAssets(mContext.getAssets(), "pretty.otf");

paint.setTypeface(myTypeface);

画像のようにテキストの間隔を空けるには、次のように文字列に \n 文字を追加して新しい行を追加します。

canvas.drawTextOnPath("There are\n137 days, 9 Hour\n4 Minutes and 36 seconds\nuntil Christmas", circle, 0,30,paint);
于 2012-06-03T21:13:17.683 に答える