我想嚮導航抽屜添加垂直線性佈局(在底部有一個標題,圖像,菜單標題,列表視圖和圖標)。然而,應用程序崩潰顯示將線性佈局添加到導航抽屜(最終因ClassCastException而崩潰)
'java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams'
錯誤。我不確定這是否可能的直線方式,因爲我檢查了幾個鏈接,我得到的唯一結果是this.任何幫助表示讚賞。 在此先感謝。 這是我的代碼。
<!-- The main context view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#fff"
android:gravity="bottom|center"
android:orientation="vertical"
android:paddingTop="30dp" >
<ListView
android:id="@+id/left_drawer"
android:choiceMode="singleChoice"
android:divider="#E8E8E8"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="@drawable/footer_image" />
</LinearLayout>
現在,這裏的問題是,XML是不是讓我來定義的寬度和高度爲ListView(元素是未知的),我也沒能爲編譯器說:「你運行它必須提供一個layout_width「屬性?請幫忙。
我的代碼與滾動視圖。
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main context view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ScrollView
android:id="@+id/leftRL"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="5dp"
android:background="#fff" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:src="@drawable/ic_launcher"
android:text="Dummy"
android:textColor="#2E3192"
android:textStyle="bold" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#2E3192" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="2dp" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#e8e8e8"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dummy name"
android:textSize="15sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[email protected]"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingBottom="3dp"
android:src="@drawable/ic_launcher"
android:text="Dummy item"
android:textColor="#2E3192"
android:textStyle="bold" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#2E3192" />
</LinearLayout>
<ListView/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:padding="10dp"
android:src="@drawable/footer_image" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
我相信它應該允許你 –
它的確,我必須輸入整個事情。再次感謝。 –
還有一個問題,我希望整個頁面不僅滾動列表視圖,所以我添加滾動視圖頂部使父線性佈局其子作爲scrollview應該只有一個孩子。它編譯,但生成的輸出只顯示列表中的1項,即使屏幕上有空間。以上是我的代碼。 –