【问题标题】:Navigation view height I have set to match_parent but it doesn't really match the parent at all我已设置为 match_parent 的导航视图高度,但它根本不匹配父级
【发布时间】:2017-07-13 03:53:24
【问题描述】:

我设置为 match_parent 的导航视图高度,但它根本不匹配父级 下面是xml代码:

<?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="start">

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content">
    </FrameLayout>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/moveimage"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_launcher"/>
    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
       android:fitsSystemWindows="true"
        android:background="#fff"
        app:headerLayout="@layout/nav_header" />
</android.support.v4.widget.DrawerLayout>

对于navigationView的高度,如何让它适合整个屏幕

截图如下:

【问题讨论】:

  • 相对布局没有方向属性
  • @Yasharyan 什么是方向属性?那么我应该改变什么?
  • 您有 2 个相对布局。第一个有android:orientation="vertical" 行。去掉它。请注意确定这是否可以解决任何问题,但这是不正确的做法。
  • @Yasharyan 已将其删除,但它并没有像您所说的那样修复任何问题
  • @TommyChong:你采用第二个相对布局的目的是什么?是否要在 NavigationView 中添加?

标签: android xml drawerlayout navigation-drawer android-navigationview


【解决方案1】:

试试下面可能对你有帮助:

<?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="start">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/lytMain"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
</LinearLayout>
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/side_nav_bar">

        <ImageView
            android:id="@+id/moveimage"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@mipmap/ic_launcher" />
    </RelativeLayout>
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    相关资源
    最近更新 更多