문제

I want to implement a Navigation Drawer (left menu) in Android.

The menu should have a list of items at the top and a footer with two buttons on the bottom.

I have taken two approaches:

1) Add a footer to the list via

mDrawerList.addFooterView(footer);

With this solution the footer is like another item of the list. So if the list has few items, then the footer doesn't show in the bottom, in fact it is right below the last list item.

2) Apply a Relative Layout to the left component like:

<?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>

However when not all the menu list items are shown the footer is above the list items, hidding the last items.

How can I achieve the right solution?

Do I have to use a ScrollView?

Thanks!

Edited 1

Using the 2nd approach and the android:layout_above in the left_drawer RelativeLayout I get something similar to the picture taken:

enter image description here

도움이 되었습니까?

해결책

It looks to me like there is an issue with your layout. You shouldn't need two RelativeLayouts.

Try something like this:

<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>

Notice the addition of layout_above in the ListView and moving the alignParentBottom to the Button.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top