【发布时间】:2017-07-03 03:23:16
【问题描述】:
我在 DrawerLayout 中有一个 NavigationView,NavigationView 为来自屏幕左侧的抽屉提供布局。我使用它是为了向后兼容,我需要在顶部有一个图像,就像你通常在导航抽屉中一样。我已向 NavigatonView 添加了一个图像视图,但该图像视图位于我的抽屉中间。我需要它在菜单项上方的顶部。这是我的示例代码...
<?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:aapp="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_background">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<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="?attr/colorPrimaryDark"
app:menu="@menu/menu_main"
app:itemTextColor="@color/text_field_font_color">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nav_header"
android:gravity="top"
android:src="@drawable/nav_header"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
我尝试更改 android:layout_gravity 和 imageview 的 android:gravity,但没有成功。如何让这个 imageview 布局在 navigationView 的菜单项之上?
【问题讨论】:
标签: android android-layout view navigation-drawer