Reputation: 14370
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?
Upvotes: 1
Views: 20554
Reputation: 10622
Use this..
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,getWindowManager().getDefaultDisplay().getHeight()-100));
Upvotes: 6
Reputation: 2106
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.
Upvotes: 1
Reputation: 1969
If the _llChooseType is a LinearLayout object then I think you should use
new LinearLayout.LayoutParams(...);
Regards
Ziteng Chen
Upvotes: 2
Reputation: 411
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!
Upvotes: 0