需要帮助找出为什么我的工具栏与内容重叠。
我这里有一个工具栏布局
工具栏.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/AppTheme">
</android.support.v7.widget.Toolbar>
然后我将这个工具栏与抽屉导航一起使用,如下所示。
导航_抽屉.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.jlurena.yougothw.activities.base.NavigationDrawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
</LinearLayout>
<ListView
android:id="@+id/nav_list"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffeeeeee">
</ListView>
</android.support.v4.widget.DrawerLayout>
最后,所以我只需要扩展一个 NavigationDrawer.java,我在 NavigationDrawer.java 中设置工具栏,并在我需要的每个其他 Activity 中扩展它。然后我像这样充气
public void inflateBaseLayout(Activity activity, int resLayoutId) {
LayoutInflater inflater =
(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Inflate Navigation Drawer in activity
View view = inflater.inflate(resLayoutId, null, true);
drawer.addView(view, 0); // Where drawer is the DrawerLayout from navigation_drawer.xml
}
我对工具栏到底做错了什么?
最佳答案
将 ListView
放入 LinearLayout
中包含工具栏之后。这应该会让一切都井然有序。
关于java - 工具栏重叠内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43458215/