android 在代码中动态的变更wight和height注意事项 Caused by: java.lang.ClassCastException:android.widget.LinearLayou
2014-09-18 10:12
621 查看
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/FrameLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
若想在代码中动态改变FrameLayout的大小,应该这样写:
FrameLayout frameLayout=(FrameLayout) convertView.findViewById(R.id.FrameLayout01);
//注意这里是通过父类获取 new LinearLayout.LayoutParams,而使用时是使用在FrameLayout上
LinearLayout.LayoutParams ff=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, height);
frameLayout.setLayoutParams(ff);
如果不通过上面的方式设置的话,会出现
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/FrameLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
若想在代码中动态改变FrameLayout的大小,应该这样写:
FrameLayout frameLayout=(FrameLayout) convertView.findViewById(R.id.FrameLayout01);
//注意这里是通过父类获取 new LinearLayout.LayoutParams,而使用时是使用在FrameLayout上
LinearLayout.LayoutParams ff=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, height);
frameLayout.setLayoutParams(ff);
如果不通过上面的方式设置的话,会出现
Caused by: java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
相关文章推荐
- 莫明的Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- 代码改布局的高度等Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- 开发问题及解决 java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- 转 Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- setLayoutParams 开发问题及解决 java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.LinearLayout
- 开发问题及解决 java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- xml修改后报错: java.lang.ClassCastException: android.widget.LinearLayout
- Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Bu
- java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- Caused by: java.lang.ClassCastException: android.widget.TextView修复
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout