【问题标题】:Android Navigatoin Drawer (Menu) with scrollable footer带有可滚动页脚的 Android 导航抽屉(菜单)
【发布时间】: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


    【解决方案1】:

    在我看来,您的布局有问题。你不应该需要两个RelativeLayouts。

    试试这样的:

    <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:layout_above="@+id/dashboard_iv_profile_image"
      android:background="@color/black"/>
    
      <Button
        android:id="@+id/dashboard_iv_profile_image"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_alignParentBottom="true"
        android:layout_margin="20dp"
        android:text="Test"/>
    
    </RelativeLayout>
    

    注意 ListView 中添加了 layout_above 并将 alignParentBottom 移动到 Button

    【讨论】:

    • 额外的相对布局是因为我有多个按钮。我尝试了 android:layout_above 属性,但是当我将方向更改为横向时,页脚位于列表顶部,隐藏了最后一项。我编辑了问题以显示来自 Google 的图片应用程序的图像,该图像具有相同的结果,这不是我所期望的,但带有标题。
    • 对于两个按钮,您仍然不需要另一个 RelativeLayout。玩弄布局,你会明白的。因此,无需旋转屏幕,我的解决方案就可以工作。现在你有一个新问题是你的布局在屏幕旋转后发生了变化?
    • @gonzalomelov 如果对您有帮助,请随时接受这个答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 2015-11-04
    • 2014-08-20
    • 2017-05-05
    相关资源
    最近更新 更多