Android 抽屉布局与其他项目重叠
我在试着制作菜单 要构建此菜单,我使用抽屉布局 但是我在显示抽屉布局时遇到了一些问题,因为我的列表视图与所有内容重叠 我需要对XML代码进行哪些更改来防止这种情况 我的菜单: 列表视图与菜单重叠 我的代码:Android 抽屉布局与其他项目重叠,android,xml,Android,Xml,我在试着制作菜单 要构建此菜单,我使用抽屉布局 但是我在显示抽屉布局时遇到了一些问题,因为我的列表视图与所有内容重叠 我需要对XML代码进行哪些更改来防止这种情况 我的菜单: 列表视图与菜单重叠 我的代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:andro
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="horizontal"
tools:context=".MainActivity" >
<include
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/toolbar" />
<!-- Menu -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bar" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#029688"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
<!-- Listview is here -->
<ListView
android1:id="@+id/lvevents"
android1:layout_width="match_parent"
android1:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="9dp"
android1:layout_alignParentLeft="true"
android1:layout_alignParentRight="true"
android1:layout_below="@+id/bar"
android:dividerHeight="6dp"
android:scrollbars="none" >
</ListView>
<ImageView
android1:id="@+id/imgvloading"
android1:layout_width="64dp"
android1:layout_height="64dp"
android:layout_centerInParent="true"
android:gravity="center" />
</RelativeLayout>
谢谢。您的
抽屉布局应该是根布局,例如:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Place your main content here -->
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/frame_parent"/>
<!-- And the layout for your nav menu here -->
<android.support.v7.widget.RecyclerView
android:id="@+id/navigation_menu_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:scrollbars="vertical"
android:background="#ff1cac"
/>
</android.support.v4.widget.DrawerLayout>
通常,抽屉布局是活动的根布局。抽屉布局的第一个子视图是您的内容,第二个子视图是您的实际抽屉。尝试重新排列到以下位置,并根据需要进行调整:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android_layout_height="match_parent">
<include
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_below="@id/bar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/lvevents"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="9dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/bar"
android:dividerHeight="6dp"
android:scrollbars="none" />
<ImageView
android:id="@+id/imgvloading"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:gravity="center" />
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#029688"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
此外,您应该删除不必要的xmlns:android1
声明,并用android
替换您使用过的任何实例(这在我提供的示例中已经完成)您的“列表视图”必须放在“内容”框架内,并且“抽屉布局”应用作根视图:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bar">
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/bar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android1:id="@+id/lvevents"
android1:layout_alignParentLeft="true"
android1:layout_alignParentRight="true"
android1:layout_below="@+id/bar"
android1:layout_height="wrap_content"
android1:layout_width="match_parent"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="9dp"
android:dividerHeight="6dp"
android:scrollbars="none">
</ListView>
</LinearLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#029688"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>