0

こんにちは、キャンバスに四角形を追加したので、その四角形にテキストビューまたはその他のビューを追加したいと思います。チュートリアルも提案してください。前もって感謝します

public class DrawView extends View {

    public DrawView(Context context) {
        super(context);
    }
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Rect rect = new Rect();
        rect.set(20 ,10 ,canvas.getWidth()/2, canvas.getHeight()/2);
        Paint paint = new Paint();
        paint.setColor(Color.GREEN);
        canvas.drawRect(rect, paint);
    }
}
4

2 に答える 2

0

キャンバスにテキストを描画できます。

        Paint mpaint= new Paint();
        mpaint.setColor(Color.RED);//set red color for rectangle
        mpaint.setStyle(Paint.Style.FILL);//mpaint will fill the rectangle
        Paint paint2 = new Paint();
        paint2.setColor(Color.GREEN);//green color for text
        paint2.setTextSize(30f);//set text size. you can change the stroke width also

@Override
protected void onDraw(Canvas canvas)
     {
   canvas.drawRect(30, 30, 600, 600, mpaint);
   canvas.drawText("hello", 150, 150, paint2);//change x and y according to your needs
     }

サムスン ギャラクシー s3 の結果のスナップショット ここに画像の説明を入力

于 2013-03-23T14:59:37.343 に答える
0

単にキャンバスに描画しているだけなので、ここではあらゆる種類のビューを追加することは問題外です。しかしCanvas.drawText(...)、まさにあなたが探しているものかもしれません。

于 2013-03-23T11:24:00.873 に答える