代码之家  ›  专栏  ›  技术社区  ›  ADB

可动态更改大小的按钮

  •  0
  • ADB  · 技术社区  · 15 年前

    我已经创建了一个自定义按钮类,我希望能够根据内容宽度/高度之外的一些因素更改其宽度/高度。我该怎么做?

    • 我试过做setwidth/setheight,但没有效果。
    • I have set the layout_width/height to wrap_content and tried to override the function that calculates the content size, but I can't find it either.

    我是刚接触Android的,所以我打赌我错过了一些非常明显的东西,所以请启发我。

    1 回复  |  直到 15 年前
        1
  •  1
  •   ADB    15 年前

    好的,我想了一下:重写onMeasure函数。

       protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int w = <calculation>
          int h = <calculation>
          setMeasuredDimension(w, h);
       }