2016-02-18 1 views
3

Как добавить нижний колонтитул в NavigationView? В моем случае товары меню NavigationView завышены ресурсом меню. Сначала я попытался добавить LinearLayout в качестве нижнего колонтитула, но NavigationView не прокручивается, а нижний колонтитул перекрывается элементами меню навигации. Я хочу осуществить рейтинговую Play сегмент Google как сноске точно, как это изображение:Как добавить нижний колонтитул в навигационный ящик в Android с помощью библиотеки поддержки дизайна?

enter image description here

navigation_drawer.xml:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:id="@+id/toolbar" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:title="@string/app_name" /> 

    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:id="@+id/drawerLayout"> 

    <FrameLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/containerView"> 
    </FrameLayout> 

    <android.support.design.widget.NavigationView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:id="@+id/shitstuff" 
     app:itemTextColor="@color/green" 
     app:menu="@menu/drawermenu" 
     app:headerLayout="@layout/drawer_header" 
     android:layout_marginTop="-24dp"> 
    </android.support.design.widget.NavigationView> 

    </android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

ответ

8

Это действительно просто:

просто обернуть нужный колонтитул в вашей NavigationView. Вы можете использовать мой в качестве примера - работает как шарм!

<android.support.design.widget.NavigationView 
    android:id="@+id/nvView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@android:color/white" 
    app:headerLayout="@layout/navigation_header" 
    app:itemTextColor="@android:color/black" 
    app:menu="@menu/drawer_view"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:clickable="true" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/nav_footer_textview" 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      android:gravity="center" 
      android:text="Your Footer Text Here" /> 

    </LinearLayout> 

</android.support.design.widget.NavigationView> 

Вы можете использовать любой (более или менее сложный) макет таким образом. (Afaik этот нижний колонтитул не будет прокручиваться и будет исправлен).

+5

на маленьких экранах (и/или ориентации на земле) меню в NavigationView будет перекрывать нижние колонтитулы - попробовал с RelativeLayout – Droidman

2

Вы можете использовать NavigationView

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout_dashboard" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <!-- Activity content goes here --> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_drawer_container" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start"> 

     <android.support.design.widget.NavigationView 
      android:id="@+id/navigation_drawer" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="top" 
      app:menu="@menu/menu_navigation_drawer" /> 

     <android.support.design.widget.NavigationView 
      android:id="@+id/navigation_drawer_bottom" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      app:menu="@menu/menu_navigation_drawer_bottom" /> 

    </android.support.design.widget.NavigationView> 

</android.support.v4.widget.DrawerLayout> 

http://answermega.livedoor.biz/archives/1038944871.html

https://github.com/mikepenz/MaterialDrawer

https://github.com/rudsonlive/NavigationDrawer-MaterialDesign

+0

Это работает, но нижний ящик находится выше верхняя, поэтому вы должны добавить манекен предметов к нему. –

+0

как обращаться с прокруткой, пункты меню теперь скрыты за этим видом. –

+0

Как удалить горизонтальную высоту с внутреннего вида навигации? –

0
<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:itemIconTint="@color/colorAccent" 
    app:menu="@menu/activity_main_drawer"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:clickable="true" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/nav_footer_textview" 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      android:gravity="center" 
      android:text="Your Footer Text Here" /> 

    </LinearLayout> 
</android.support.design.widget.NavigationView> 

И для выполнения нажмите на него:

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
TextView footerTV = (TextView) navigationView.findViewById(R.id.nav_footer_textview); 
footerTV.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     Toast.makeText(MainActivity.this, "Footer is clicked", Toast.LENGTH_SHORT).show(); 
    } 
}); 
+0

Не могли бы вы добавить информацию о том, как это отличается от других ответов? –