1

I have a Linearlayout in my xml which has fill_parent for both height and width... Now i want to dynamically change the height and width... I tried Using

_llChooseType.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,getWindowManager().getDefaultDisplay().getHeight()-100)); 

But it is giving me java.lang.ClassCastException: android.view.ViewGroup$LayoutParams exception...

How to do it?

1
  • Not sure about this so this is a comment but if I remember correctly you can do getLayoutParams() or something similar on your layout itself to gets it's correct layout params. Commented Jun 9, 2011 at 8:07

4 Answers 4

6

Use this..

new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,getWindowManager().getDefaultDisplay().getHeight()-100)); 
Sign up to request clarification or add additional context in comments.

Comments

2

If the _llChooseType is a LinearLayout object then I think you should use

new LinearLayout.LayoutParams(...); 

Regards

Ziteng Chen

Comments

1

The setLayoutParams widht & height can only have the following 3 values: FILL_PARENT, MATCH_PARENT and WRAP_CONTENT.

You should use public void layout (int l, int t, int r, int b) To actually change the layout of the created view/viewgroup.

Comments

0

Do this... Type:

_llChooseType.setLayoutParams(new Layo 

and press ctrl+space_bar. This will give you a list of LayoutParams options to choose from...select LinearLayout.LayoutParams and write the rest of the code as is. The problem here is that the LayoutParams you use are ViewGroup.LayoutParams and they don't apply to linear layouts!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.