【发布时间】:2016-10-02 03:52:34
【问题描述】:
我的类 Triangle 从 View 扩展而来,它的 onDraw 方法包括:
... onDraw(){
...
drawCircle(anyx, anyy, anyradius, anypaint);
}
还有我想在其中创建 Button 和 Circle 的 Activity,它们都是动态创建的。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newexample);
RelativeLayout viewGroup = (RelativeLayout)findViewById(R.id.visiont);
Button b1 = new Button(this);
viewGroup.addView(b1);
b1.setX(140); // Position of the button
b1.setY(140);
ViewGroup.LayoutParams params = b1.getLayoutParams();
params.height=80; // Size of the button
params.width=80;
b1.setLayoutParams(params); // Deleting this does not change the behaviour of what I am getting (only changes the height and width)
Circle c = new Circle(this);
c.setColor(Color.DKGRAY);
c.setCircle(150,130,80);
viewGroup.addView(c);
}
期望结果的示例,矩形是按钮。
我现在得到的是相反的,按钮在圆圈上方。
【问题讨论】:
-
尝试先添加您的圈子,然后将按钮添加到您的相关布局中
-
它不起作用。没有任何变化。
标签: android button layout dynamic geometry