[英]Draw a circle partially inside on a button dynamically android
My class Triangle extends from View and its method onDraw consists of: 我的类Triangle从View扩展而来,其方法onDraw包括:
... onDraw(){
...
drawCircle(anyx, anyy, anyradius, anypaint);
}
And the Activity in which I want to create the Button and the Circle, both created dynamically. 我想在其中创建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);
}
An example of what is the desired result, the rectangle is the button. 所需结果的一个示例是矩形,它是按钮。
What I am getting now is the opposite, the button is over the circle. 我现在得到的恰恰相反,按钮在圆圈上。
I tried to switch Button to ImageButton since I wanted to have a custom image in the button (Actually I wanted a clickable component) 我试图将Button切换为ImageButton,因为我想在按钮中添加自定义图像(实际上,我想要一个可点击的组件)
It appears that, with only switching Button to ImageButton, works as desired, so, for me it's a suitable solution. 看来,仅将Button切换到ImageButton即可按需要工作,因此,对我来说,这是一个合适的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.