views:

36

answers:

0

I am trying to programmatically resize a custom view in android. The custom view contains a Button and an EditText in a LinearLayout. I want to make several instances of this custom view and alter the width of each one slightly narrower than the last so that they overlap each other. At what point can I do this and how?

If I override the custom view's onWindowFocusChanged() to set the width using this.setLayoutParams( newWidth, LayoutParams.FILL_PARENT); it crashes later on with a ClassCastException in the LinearLayout. Like this...

@Override
 public void onWindowFocusChanged( boolean changed )
{
    super.onWindowFocusChanged( changed );

    // reset the width
    int fullWidth = this.getWidth();
    if( fullWidth > 0 )
    {
        int width = fullWidth - (20 * (viewNumber));
        this.setLayoutParams(new LinearLayout.LayoutParams( width, LayoutParams.FILL_PARENT));
    }
}

So, obviously, this is not the way to do it. How then?

Thanks.