Android 将视图添加到画布中绘制的圆上的线性布局
我用画布绘制法画了一个圆。现在我想添加一个关于圆周的视图。我可以得到圆的坐标,但完全不知道如何将视图添加到该坐标 守则如下—Android 将视图添加到画布中绘制的圆上的线性布局,android,android-layout,android-linearlayout,android-canvas,android-custom-view,Android,Android Layout,Android Linearlayout,Android Canvas,Android Custom View,我用画布绘制法画了一个圆。现在我想添加一个关于圆周的视图。我可以得到圆的坐标,但完全不知道如何将视图添加到该坐标 守则如下— public class CircleView2 extends LinearLayout { private int centerX, centerY; private float fixedRadius = 30; private Paint paint; private Logger logger; private Cont
public class CircleView2 extends LinearLayout {
private int centerX, centerY;
private float fixedRadius = 30;
private Paint paint;
private Logger logger;
private Context context;
TextView textView;
public CircleView2(Context context) {
super(context);
setWillNotDraw(false);
doInit(context);
}
public CircleView2(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
doInit(context);
}
private void doInit(Context context) {
this.context = context;
logger = new Logger(context);
fixedRadius = 30;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
paint.setColor(Color.rgb(227, 73, 90));
textView = new TextView(context);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
centerX = w / 2;
centerY = h / 2;
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawCircle(centerX, centerY, fixedRadius + 160, paint);
double x = centerX + (fixedRadius + 160) * Math.cos(Math.toDegrees(45.0));
double y = centerY + (fixedRadius + 160) * Math.sin(Math.toDegrees(45.0));
logger.debug(x + "");
logger.debug(y + "");
textView.setTextColor(Color.BLACK);
textView.setText("AAA");
textView.draw(canvas);
super.onDraw(canvas);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
}
这画圆很好。但无法添加文本视图textview.draw(画布)
应该将其添加到视图中,对吗?如何将textview添加到view,并在计算坐标处将其添加到
我做错了什么 扩展ViewGroup并覆盖它的onLatout方法,为每个孩子调用layout()。您是否找到了解决方案?@Jovan这是一个很老的问题。但是是的,我在某种程度上解决了这个问题。它有一些我记不清楚的问题,但试一下。代码发布在那里@sachingute,谢谢。我自己设法做到了。由于某种原因,我在计算合适的尺寸时遇到了问题。我相信这对某些人会有用的。很好的解决方案。:)