【问题标题】:Draw a circle partially inside on a button dynamically android在一个按钮上动态地在android内部画一个圆圈
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 2012-11-12
    • 2019-05-11
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多