CoordinatorLayout 背后的内容 AppBarLayout
Content behind CoordinatorLayout AppBarLayout
我正在为我的应用程序创建设置 activity/layout。我有一个带有 AppBarLayout
和 Toolbar
的 CoordinatorLayout
,然后在其下方包含 content_settings.xml
。当内容加载时,.xml 文件位于应用栏后面。
我正在使用相同的设置来加载主要内容并且工作正常,但由于某种原因在“设置”部分中无法正确呈现。
activity_settings.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_setting" />
content_settings.xml 只是一个 FrameLayout
被 PreferenceFragment
取代
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
将此添加到您的 Recyclerview 中:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
在我的例子中,工具栏下方的视图不可滚动,因此即使接受的答案确实停止了重叠,它也会将内容向下推工具栏的高度,将元素推离屏幕。
在这种情况下的解决方案是也删除
app:layout_scrollFlags
来自我 including/sharing 具有滚动视图的其他布局的工具栏。
我正在为我的应用程序创建设置 activity/layout。我有一个带有 AppBarLayout
和 Toolbar
的 CoordinatorLayout
,然后在其下方包含 content_settings.xml
。当内容加载时,.xml 文件位于应用栏后面。
我正在使用相同的设置来加载主要内容并且工作正常,但由于某种原因在“设置”部分中无法正确呈现。
activity_settings.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_setting" />
content_settings.xml 只是一个 FrameLayout
被 PreferenceFragment
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
将此添加到您的 Recyclerview 中:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
在我的例子中,工具栏下方的视图不可滚动,因此即使接受的答案确实停止了重叠,它也会将内容向下推工具栏的高度,将元素推离屏幕。 在这种情况下的解决方案是也删除
app:layout_scrollFlags
来自我 including/sharing 具有滚动视图的其他布局的工具栏。