我有一个奇怪的导航抽屉行为。当我使用以下布局时,当我打开导航抽屉时,它会在listView1和adlay后面打开。这意味着抽屉被listView1和adlay部分隐藏。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/header_bg"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ListView
android:id="@+id/drawer_list"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#eee"
android:dividerHeight="1dp"
android:background="#fff"
android:layout_below="@+id/toolbar"
>
</ListView>
</android.support.v4.widget.DrawerLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adlay"
android:layout_below="@+id/toolbar"
android:layout_margin="7dp"
android:cacheColorHint="#00000000"
android:divider="@android:color/transparent"
android:dividerHeight="3dp">
</ListView>
<LinearLayout
android:id="@+id/adlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
但是,如果我稍微更改排序,请使用以下布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/header_bg"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adlay"
android:layout_below="@+id/toolbar"
android:layout_margin="7dp"
android:cacheColorHint="#00000000"
android:divider="@android:color/transparent"
android:dividerHeight="3dp">
</ListView>
<LinearLayout
android:id="@+id/adlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
</LinearLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ListView
android:id="@+id/drawer_list"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#eee"
android:dividerHeight="1dp"
android:background="#fff"
android:layout_below="@+id/toolbar"
>
</ListView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
然后,导航抽屉将在listView1和adlay的前面(顶部)打开,并且效果很好。但是有一个很大的问题,即使抽屉没有打开,点击listView1和adlay也会被禁用!我无法点击工具栏上的任何内容!
以下是我的活动文件的一部分:
// get list items from strings.xml
drawerListViewItems = getResources().getStringArray(R.array.autoscroll_text);
drawerListView = (ListView) findViewById(R.id.drawer_list);
drawerListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.storylist_navigation_drawer_item, drawerListViewItems));
// App Icon
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open,
R.string.drawer_close) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
drawerView.bringToFront();
getWindow().getDecorView().requestLayout();
getWindow().getDecorView().invalidate();
}
};
// Set actionBarDrawerToggle as the DrawerListener
drawerLayout.setDrawerListener(actionBarDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer);
// just styling option add shadow the right edge of the drawer
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
我花了好几个小时试图让它正常工作。请注意我有一个工具栏,我需要在工具栏下方显示抽屉显示(目前它的行为方式)。
非常感谢任何帮助。谢谢你的时间。
答案 0 :(得分:0)
您的listview和adlay应该放在drawerlayout
中<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/header_bg"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/adlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
</LinearLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adlay"
android:layout_margin="7dp"
android:cacheColorHint="#00000000"
android:divider="@android:color/transparent"
android:dividerHeight="3dp">
</ListView>
</RelativeLayout>
<ListView
android:id="@+id/drawer_list"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#eee"
android:dividerHeight="1dp"
android:background="#fff"
android:layout_below="@+id/toolbar">
</ListView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>