[英]How to set the height and width of linear layout dynamically in android
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我的 xml 中有一个 Linearlayout,它的高度和宽度都有 fill_parent ......现在我想动态改变高度和宽度......我试过使用
_llChooseType.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,getWindowManager().getDefaultDisplay().getHeight()-100));
But it is giving me java.lang.ClassCastException: android.view.ViewGroup$LayoutParams exception...但它给了我 java.lang.ClassCastException: android.view.ViewGroup$LayoutParams 异常......
How to do it?怎么做?
Use this..用这个..
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,getWindowManager().getDefaultDisplay().getHeight()-100));
If the _llChooseType is a LinearLayout object then I think you should use如果 _llChooseType 是 LinearLayout object 那么我认为你应该使用
new LinearLayout.LayoutParams(...);
Regards问候
Ziteng Chen陈子腾
The setLayoutParams widht & height can only have the following 3 values: FILL_PARENT, MATCH_PARENT and WRAP_CONTENT. setLayoutParams widht & height 只能有以下 3 个值:FILL_PARENT、MATCH_PARENT 和 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.您应该使用public void layout (int l, int t, int r, int b)
来实际更改创建的视图/视图组的布局。
Do this... Type:这样做... 键入:
_llChooseType.setLayoutParams(new Layo
and press ctrl+space_bar.然后按 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.这将为您提供 LayoutParams 选项列表以供您选择...select LinearLayout.LayoutParams 并按原样编写代码的 rest。 The problem here is that the LayoutParams you use are ViewGroup.LayoutParams and they don't apply to linear layouts!这里的问题是您使用的 LayoutParams 是 ViewGroup.LayoutParams 并且它们不适用于线性布局!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.