【发布时间】:2014-06-04 19:54:12
【问题描述】:
我想在 Android 中实现一个导航抽屉(左侧菜单)。
菜单顶部应该有一个项目列表,底部应该有一个带有两个按钮的页脚。
我采取了两种方法:
1) 在列表中添加页脚
mDrawerList.addFooterView(footer);
使用此解决方案,页脚就像列表中的另一个项目。因此,如果列表中的项目很少,则页脚不会显示在底部,实际上它就在最后一个列表项的正下方。
2) 将相对布局应用到左侧组件,例如:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- The navigation drawer -->
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start">
<ListView
android:id="@+id/left_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/white"
android:dividerHeight="1dp"
android:background="@color/black"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="20dp">
<Button
android:id="@+id/dashboard_iv_profile_image"
android:layout_width="90dp"
android:layout_height="90dp"
android:text="Test"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
但是,当没有显示所有菜单列表项时,页脚位于列表项上方,隐藏了最后一项。
我怎样才能获得正确的解决方案?
我必须使用 ScrollView 吗?
谢谢!
已编辑 1
使用第二种方法和 left_drawer RelativeLayout 中的 android:layout_above 我得到类似于所拍照片的东西:
【问题讨论】:
标签: android menu navigation-drawer