导航抽屉布局与框架布局重叠

时间:2016-10-27 19:04:27

标签: android navigation-drawer

每当我打开我的导航抽屉框架布局内容都会在背景中显示我甚至尝试设置框架的颜色为白色

main_activity.xml

 <?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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
tools:context="com.example.sumanravi.knowmycity.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
     android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content_layout"
        android:background="@color/white">
    </FrameLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:orientation="vertical">
    <ListView
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:id="@+id/navList"
        android:choiceMode="singleChoice">
    </ListView>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

如果你想要隐藏布局的内容,你可以:

  1. 隐藏整个布局(将可见性设置为View.GONEView.VISIBLE
  2. 更改alpha(在布局本身上设置alpha)
  3. 删除所有布局的孩子(请不要使用此方法,这非常愚蠢)
  4. 包含视图将始终在其下方绘制父级背景。隐藏内容的另一种有趣方式是使用抽屉监听器:https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html#onDrawerSlide(android.view.View,浮动) - 查找onDrawerSlide(View, float)方法并(例如)随时更改视图的alpha。

    使用FrameLayouts可以做的另一件事是设置前景:set forground color in framelayout in android programatically

    但通常情况下,导航抽屉下的内容始终(至少部分)可见。如果您试图隐藏它,则可能不会关注the guide