android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam

来源:互联网 发布:万花成男捏脸数据 编辑:程序博客网 时间:2024/05/17 09:25

布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/RelativeLayout02"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="250dp"        android:id="@+id/linear_control_hor"        android:orientation="horizontal">
代码:

LinearLayout.LayoutParams linearParams =        (LinearLayout.LayoutParams) LAdLiLayoutControl.getLayoutParams();linearParams.height = pxHeightValue;LAdLiLayoutControl.setLayoutParams(linearParams);
 

原因:控件 getLayoutParams()      获取的是父控件的LayoutParams,父控件就是上一级控件 RelaytiveLayout

修改为:

RelativeLayout.LayoutParams relativeParams =        (RelativeLayout.LayoutParams) LAdLiLayoutControl.getLayoutParams();

如果布局是:

<RelativeLayout    android:layout_width="150dp"    android:layout_height="250dp"    android:id="@+id/L_bannerAD_ver_rl"    android:visibility="visible">    <ImageView        android:id="@+id/L_bannerAD_ver_img"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:src="@drawable/advertise"        android:scaleType="fitXY"        android:adjustViewBounds="true">    </ImageView>
那么imageview.getLayoutParams 是 RelativeLayout。



                                                       

0 0
原创粉丝点击