android - coordinatorlayout 中的 actionbar 和布局相互重叠

标签 android android-layout

我在我的 android 应用程序中使用 coordinatorlayout 并定义如下

<android.support.design.widget.CoordinatorLayout 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:theme="@style/Theme.AppCompat.Light.DarkActionBar"
                                             tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_activity_main"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<include
    layout="@layout/content_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/test"/>

测试布局是 LinearLayout,它有更多的 View

问题是操作栏与测试布局的内容重叠

这可能是因为主题? (我个人感觉不到)但不确定

最佳答案

你应该试试这个,

主题不是真正的问题。

<android.support.design.widget.CoordinatorLayout 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:theme="@style/Theme.AppCompat.Light.DarkActionBar"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:id="@+id/main"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_activity_main"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <include
        layout="@layout/content_main"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_height="wrap_content"
        android:id="@+id/test"/>
    </android.support.design.widget.CoordinatorLayout>

关于android - coordinatorlayout 中的 actionbar 和布局相互重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42023308/

相关文章:

java - Android单列Gridview

android-layout - 在 surfaceView 上添加一个可点击按钮

Android 布局主题样式

android - 将 SurfaceView 与其他 View (如 TextView 和 Buttons)组合

android - 如何为所有 Activity 创建通用的 Android XML 布局

android - 如何为 android 创建类似 ibook 书架的用户界面?

android - android :exported ="false" restrict system calls/access?吗

android - 如何以编程方式查找 USB 存储路径?

android - 四方转二维码

java - 如何在完成一首歌后播放下一首歌曲?