Android 抽屉布局中视图的大小和单击行为错误
我有一个Android 抽屉布局中视图的大小和单击行为错误,android,android-layout,drawerlayout,Android,Android Layout,Drawerlayout,我有一个活动的布局,我正试图在其中添加导航抽屉 问题是,要正常工作,我需要使用: <android.support.v4.widget.DrawerLayout 如何创建抽屉菜单而不破坏其他一切?任何不是抽屉的抽屉布局的直接子视图都被视为内容视图,并将在两个方向上进行布局以匹配父视图,而不管您在其上设置的宽度和高度属性如何。在您的情况下(实际上,在大多数情况下),您只需要一个内容视图,因此非抽屉视图的其余部分都应该位于单个视图组中 我们将把你的ProgressBar和RecyclerVi
活动
的布局,我正试图在其中添加导航抽屉
问题是,要正常工作,我需要使用:
<android.support.v4.widget.DrawerLayout
如何创建抽屉菜单而不破坏其他一切?任何不是抽屉的抽屉布局的直接子视图都被视为内容视图,并将在两个方向上进行布局以匹配父视图,而不管您在其上设置的宽度和高度属性如何。在您的情况下(实际上,在大多数情况下),您只需要一个内容
视图
,因此非抽屉视图
的其余部分都应该位于单个视图组
中
我们将把你的ProgressBar
和RecyclerView
都放在一个RelativeLayout
中,作为内容视图
,它们将保留你设置的布局属性。例如:
<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"
tools:context="com.st.mf.UserAreaActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin"
android:background="#fff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@layout/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
请注意,内容
视图
应始终列在任何抽屉之前,以保持正确的z顺序;i、 例如,将抽屉放在内容的顶部。抽屉布局
应该只有一个内容视图
。将您的进度条
和回收视图
都放在视图组
中,就像垂直线性布局一样
@MikeM。非常感谢你。你介意给我举个例子,让我能更好地形象化吗?你是说一个布局XML的例子吗?@MikeM。使用我的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"
tools:context="com.st.mf.UserAreaActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="@dimen/activity_vertical_margin"
android:background="#fff">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp" />
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@layout/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<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"
tools:context="com.st.mf.UserAreaActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin"
android:background="#fff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@layout/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>