java.lang.ClassCastException android.widget.RelativeLayout LayoutParams 異常

一、在xml佈局文件以下所示:java

<RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/darker_gray"
                android:paddingBottom="5dp"
                android:paddingTop="5dp" >

                <View
                    android:id="@+id/slide_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/slide_background" />

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <RelativeLayout
                        android:id="@+id/rl_conversation"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" >

二、在java.class文件中獲取控件mSlideView的佈局參數getLayoutParams, 運行過程當中出現android

java.lang.ClassCastException android.widget.RelativeLayout LayoutParams 異常,通過查找資料,發現引用包錯了。ide

// 獲得會話佈局的參數,設置給滑塊 ( 由於這個view的父佈局是 RelativeLayout)佈局

LayoutParams lp = (LayoutParams) mSlideView.getLayoutParams();
因此得引用 import android.widget.RelativeLayout.LayoutParams;

不能引用系統默認引用的包 import android.widget.LinearLayout.LayoutParams;spa

相關文章
相關標籤/搜索