【问题标题】:Draw text inside oval within another oval on canvas android在画布android上的另一个椭圆内的椭圆内绘制文本
【发布时间】:2015-04-02 20:41:16
【问题描述】:

我有使用 android canvas 在椭圆内绘制椭圆的新要求。现在在椭圆内完成了椭圆,但没有在椭圆内绘制文本。下面添加的示例图像供参考。

【问题讨论】:

标签: android


【解决方案1】:

分辨率 (480 x 800)

在 onCreate() 中

setContentView(new SampleView(this));

创建类

private static class SampleView extends View {

    // CONSTRUCTOR
    public SampleView(Context context) {
        super(context);
        setFocusable(true);

    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(Color.WHITE);

        //1
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.GRAY);
        RectF oval1 = new RectF(0, 0, 250,250);

        Paint p1 = new Paint();
        p1.setColor(Color.BLACK);

        canvas.drawText("Parent", 30, 50, p1);
        canvas.drawOval(oval1, paint);


        //2
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLUE);
        RectF oval2 = new RectF(50, 50, 150, 150);

        Paint p2 = new Paint();
        p2.setColor(Color.GREEN);

        canvas.drawText("Child", 75, 75, p2);
        canvas.drawOval(oval2, paint);
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 2011-01-11
    • 2014-06-11
    • 1970-01-01
    • 2013-09-20
    相关资源
    最近更新 更多