简体   繁体   English

Android导航视图 - 项目提升

[英]Android Navigation View - items elevation

Is there a way, using the NavigationView element of the Google support library, to use elevation on the items inside a NavigationView to achieve something like this: 有没有办法,使用Google支持库的NavigationView元素,在NavigationView内的项目上使用高程来实现如下所示:

带标题高程的导航视图

You can see that the header of the navigation drawer has an elevation, like the footer on the bottom of the view. 您可以看到导航抽屉的标题有一个高程,就像视图底部的页脚一样。

I tried to use the "android:elevation" attribute but it seems to not work properly. 我试图使用“android:elevation”属性,但似乎无法正常工作。
Here's my code for the NavigationView at the moment: 这是我目前的NavigationView代码:

<?xml version="1.0" encoding="utf-8"?>
<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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="end">

    <include
        layout="@layout/app_bar_product_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_filters">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:gravity="center|end"
            android:padding="16dp"
            android:elevation="16dp"
            android:orientation="horizontal"
            tools:targetApi="lollipop">

            <TextView
                android:textAppearance="@style/TextAppearance.AppCompat.Button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Clear"/>

        </LinearLayout>

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

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

Here's the XML file for the header of the navigation view: 这是导航视图标题的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorAccent"
    android:elevation="8dp"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    tools:targetApi="lollipop">

    <android.support.v4.widget.Space
        android:layout_width="match_parent"
        android:layout_height="@dimen/status_cheat" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ordina_per"
            android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
            android:textColor="@android:color/white" />

        <android.support.v7.widget.AppCompatSpinner
            android:id="@+id/spinner_orders"
            style="@style/SpinnerStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>

As you see elevation doesn't work in this case. 如您所见,在这种情况下,高程不起作用。 How can I solve this? 我怎么解决这个问题?

Give the root layout of your header layout a layout_marginBottom so that it can get some room to display the elevation shadow. layout_marginBottom标题布局的根布局,以便它可以获得显示高程阴影的空间。

Like this: 像这样:

android:layout_marginBottom="8dp" android:elevation="4dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM