我注意到Google应用程序中的抽屉是可滚动的,但由于某些原因,我无法得出如何实现可滚动DrawerLayout的结论。我试图使用下面的设计范例来构造布局文件。
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen">
<!-- Layout of Activity -->
</FrameLayout>
<!-- DrawerLayout segment -->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/drawerLinearLayout"
android:orientation="vertical"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:layout_marginTop="?android:attr/actionBarSize"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#77000000">
<!-- Layout of Drawer -->
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>但是,不管有没有ScrollView,抽屉里的东西在屏幕结束后就会从底部剪掉。我无法启用任何形式的滚动。不知道我错过了什么或者需要启用什么。我很感激你的想法。
LinearLayout段中的DrawerLayout包含不同的样式视图。一个视图只显示标题,下面有一个分隔符,一个视图显示旁边有文本的图像视图,另一个视图显示带有行中内置开关的标题。因此,如果在XML编码的布局文件之外执行,则需要考虑多个样式的视图。
发布于 2013-10-24 13:56:38
虽然使用ListView是一个有效的选项,但对于我来说,尝试并解决已经为上述ScrollView之间的布局构造了如此大的XML文件的情况是非常有用的。事实证明,只有几个小的修改才能使它按预期工作。最近构造的布局文件如下:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen">
<!-- Layout of Activity -->
</FrameLayout>
<!-- DrawerLayout segment -->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:layout_marginTop="?android:attr/actionBarSize">
<LinearLayout
android:id="@+id/drawerLinearLayout"
android:orientation="vertical"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#77000000">
<!-- Layout of Drawer -->
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>主要的修改要求我改变重力和边缘的位置。地心引力必须在周围的ScrollView中,否则会导致奇怪的行为,在某些情况下没有滚动或实际崩溃。然后,内部布局需要更改为“包装内容”。
如果保证金也没有被移动到ScrollView中,它显然不会向下滚动到底部。它在底部留下了一个滚动的边缘。一旦解决了这个问题,DrawerLayout就会像现在所期望的那样工作。ListView选项也是另一种要使用的方法,但正如前面提到的,值得我进一步分析它,以重用我已经编写的代码;特别是需要在视图中处理的几个不同的自定义视图。
发布于 2013-11-27 23:41:12
它似乎只在ListView中才能正常工作。迁移到ListView所花费的时间要比尝试使ScrollView工作所花费的时间要少。
发布于 2013-10-23 20:11:50
您应该在框架布局的同时使用listview。就像这样:
<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">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<ListView android:id="@+id/left_drawer"
android:layout_width="180dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>您还可以参考developer.android.com上的导航抽屉文档。它有你需要的一切。
https://stackoverflow.com/questions/19551321
复制相似问题