tags:

views:

22

answers:

1

I have created a custom Button class and I want to be able to change its width/height depending on some factors in addition to the content width/height. How can I do this?

  • I have tried doing a setWidth/setHeight, but that had no effect.
  • 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.

I am new to Android so I bet I am missing something really obvious, so please enlighten me.

+1  A: 

Ok, I figured this: override the onMeasure function.

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