【问题标题】:How to draw a circle in front of a textview with canvas in android如何在android中使用画布在textview前面画一个圆圈
【发布时间】:2017-05-16 16:04:38
【问题描述】:

我编写了一个代码,其中一个圆圈移动,但每当它在 textview 前面移动时,textview 就会出现在他面前,我希望他在 textview 前面。 我在制作 textview 后尝试绘制圆圈,但它没有修复它。 示例:

public MainView(Context context) {
    super(context);
}
public void onDraw(Canvas canvas){
    ((ViewGroup) text.getParent()).removeView(text);//the text was already added to the activity
    Paint paint=new Paint();
    paint.setColor(Color.WHITE);
    canvas.drawCircle(0.0,0.0,500.0, paint);
    main.addContentView(text, parameters);//adding a textview named text in the activity
    invalidate();   
}

【问题讨论】:

    标签: android canvas view textview draw


    【解决方案1】:

    不要在 onDraw 中创建 View,它被调用了很多次,你会有很多 TextView,但你只需要一个,通常在活动 onCreate 上创建。

    TextView 显示在前面,因为绘制时子元素被剪裁,尝试在 ViewGroup 容器中将 clipChildren 设置为 false

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      相关资源
      最近更新 更多