是否有可能使用其他东西比一个ListView作为drawerlayout滑动抽屉 [英] Is it possible to use something other than a listview as sliding drawer in drawerlayout
问题描述
我想有例如的LinearLayout
或代替 RelativeLayout的
从屏幕左侧滑动一个孤独的的ListView
。
I would like to have for example a LinearLayout
or a RelativeLayout
sliding from the left of the screen instead of a lone ListView
.
我试图用的LinearLayout
与安卓layout_gravity =开始
和我有这个运行时错误
I tried to use à LinearLayout
with android:layout_gravity="start"
and i had this error at runtime:
ClassCastException: android.widget.LinearLayout$LayoutParams cannot
be cast to android.support.v4.widget.DrawerLayout$LayoutParams
这里的布局文件:
here's the layout file:
<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"
android:background="@android:color/white"
>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<ImageView
android:id="@+id/ivwLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/video_icon"
/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="320dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@android:color/white"
/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
感谢
推荐答案
是的,它可以有任何视图的抽屉布局的滑动部分。我preFER声明的FrameLayout的抽屉里和我的片段取代它,它运行得很好。
Yes it is possible to have any view as the sliding part of a drawer layout. I prefer declaring a FrameLayout as the drawer and replacing it with my fragment, and it runs just fine.
您收到该错误可能是由于在执行Java的部分其他一些原因。
The error you are getting is probably due to some other reason in the Java part of your implementation.
这篇关于是否有可能使用其他东西比一个ListView作为drawerlayout滑动抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!