11

Possible Duplicate:
Android: How to resize a custom view programmatically?

What's the best way to change width/height of a widget (I mean, a UI widget, subclass of android.view.View) programmatically?

Doing something like this works, but it doesn't seem quite right:

ViewGroup.LayoutParams params = mSomeView.getLayoutParams();
params.height += 10;
mSomeView.setLayoutParams(params);
Community
  • 1
  • 1
synic
  • 26,359
  • 20
  • 111
  • 149
  • 2
    Do you mean "widget" (i.e., subclass of `android.view.View`) or "app widget" (i.e., thingamajig that goes on the home screen)? – CommonsWare Jul 16 '10 at 13:32
  • 1
    This code works fine, You don't need third line `mSomeView.setLayoutParams(params);` – Hani Oct 18 '16 at 10:55

1 Answers1

6

I've been using this approach when to change LayoutParams attributes and it seems good enough for me. After googling i haven't found any other good way to do this.

Mojo Risin
  • 8,136
  • 5
  • 45
  • 58