如何动态设置android的FrameLayout的宽度和高度? [英] How to set Width and Height of FrameLayout dynamically android?
问题描述
我正在尝试设置2个框架布局的宽度和高度,这是2个片段的容器,这两个片段都是线性布局的子代.
I am trying to set the width and height of 2 frame layouts which are the containers for 2 fragments, both being children of a Linear Layout.
但是无论何时我用
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(100,100);
这会导致类强制转换异常
it is resulting in a class cast Exception
java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams无法转换为android.widget.LinearLayout $ LayoutParams
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
推荐答案
使用此方法...
.setLayoutParams(new LinearLayout.LayoutParams(100,100);
代替您的方法....
instead of your method ....
.setLayoutParams(new FrameLayout.LayoutParams(100,100)
注意:-ClassCastException
问题发生在您的班级与其他班级不同而您要投射...时.
Note:- ClassCastException
problem happen when your class is different other class, you want to cast....
这篇关于如何动态设置android的FrameLayout的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!