在动态android的按钮上部分画一个圆圈

时间:2016-06-02 12:03:31

标签: android button layout dynamic geometry

My class 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);
    }

所需结果的示例,矩形是按钮。

Desired result

我现在得到的是相反的,按钮在圆圈上方。

Result now

1 个答案:

答案 0 :(得分:0)

我试图将Button切换到ImageButton,因为我想在按钮中有一个自定义图像(实际上我想要一个可点击的组件)

看来,只需将按钮切换到ImageButton,就可以按需运行,因此对我来说这是一个合适的解决方案。

相关问题