【问题标题】:how to change size of button dynamic in android如何在android中更改按钮动态的大小
【发布时间】:2011-07-25 06:04:37
【问题描述】:

我尝试了 setWidth() 和 setheight() 方法,但它不起作用

【问题讨论】:

  • 使用我们动态调整按钮大小的其他方式,但首先您明确定义了您想要这种类型的功能并阅读stackOverFlow中的写入问题

标签: android android-button


【解决方案1】:

尝试使用 LayoutParams。例如

button.setLayoutParams (new LayoutParams(50, LayoutParams.WRAP_CONTENT)

【讨论】:

    【解决方案2】:

    对我来说很完美:

        ViewGroup.LayoutParams params = myButton.getLayoutParams();
        //Button new width
        params.width = 400;
    
        myButton.setLayoutParams(params);
    

    【讨论】:

      【解决方案3】:

      我发现这是最好的解决方案,因为它还允许通过简单地更改其边距来同时重新定位按钮:

      int buttonWidth = (int) (screenWidth / 3.0);
      RelativeLayout.LayoutParams params = (LayoutParams) myButton.getLayoutParams();
      params.width = buttonWidth;
      params.leftMargin = buttonWidth;
      myButton.setLayoutParams(params);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-18
        • 2011-02-24
        • 2018-02-14
        • 1970-01-01
        • 1970-01-01
        • 2020-11-17
        • 2016-01-30
        • 1970-01-01
        相关资源
        最近更新 更多