AppBarLayout 上方显示的 FrameLayout
FrameLayout Shown Above AppBarLayout
我有一个带有 AppBarLayout
和 FrameLayout
的简单 CoordinatorLayout
,但是 FrameLayout
内容显示在 AppBarLayout
之上,而不管 layout_behavior FrameLayout
上的属性。我试过在别处添加该属性(比如在我的 RecyclerView
上),但这是相同的行为。
这里有一张图来表达我的意思。
活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<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"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
片段布局:
<android.support.v7.widget.RecyclerView
android:id="@+id/checkins_recycler_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
我如何在 Activity 中添加片段:
final UserCheckinsFragment fragment = new UserCheckinsFragment();
final Bundle arguments = new Bundle();
UserCheckinsFragment.getArguments(arguments, items);
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment,
UserCheckinsFragment.class.getName()).commit();
将 app:layout_behavior="@string/appbar_scrolling_view_behavior"
添加到 RecyclerView
即可。 app:layout_behavior
应该是 Fragment
布局的根目录
xml交易中的FrameLayout
ID(@android:id/content
)和Fragment
交易中的容器(android.R.id.content
)引用系统layout的root,然后覆盖整个屏幕
要解决,请使用不带 android
前缀的它们。
In AppCompat
, there is no native support for ActionBar
.
android.R.id.content
is the container of entire app screen. This means
- including ActionBar
, because ActionBar
is emulated there and added as a standard view hierarchy.
您可能想使用(在 Layout
中):
android:id="@+id/content"
和(在Java
):
getSupportFragmentManager().beginTransaction().add(R.id.content, fragment,
UserCheckinsFragment.class.getName()).commit();
那么,它应该可以工作。
您好,我遇到了同样的问题,我通过将 "app:layout_behavior="@string/appbar_scrolling_view_behavior"" 添加到我的线性布局并包含 RecylerView 布局的布局父级中来修复它,现在它可以正常工作但是我还有一个问题,页面底部的按钮消失了
我有一个带有 AppBarLayout
和 FrameLayout
的简单 CoordinatorLayout
,但是 FrameLayout
内容显示在 AppBarLayout
之上,而不管 layout_behavior FrameLayout
上的属性。我试过在别处添加该属性(比如在我的 RecyclerView
上),但这是相同的行为。
这里有一张图来表达我的意思。
活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<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"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
片段布局:
<android.support.v7.widget.RecyclerView
android:id="@+id/checkins_recycler_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
我如何在 Activity 中添加片段:
final UserCheckinsFragment fragment = new UserCheckinsFragment();
final Bundle arguments = new Bundle();
UserCheckinsFragment.getArguments(arguments, items);
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment,
UserCheckinsFragment.class.getName()).commit();
将 app:layout_behavior="@string/appbar_scrolling_view_behavior"
添加到 RecyclerView
即可。 app:layout_behavior
应该是 Fragment
xml交易中的FrameLayout
ID(@android:id/content
)和Fragment
交易中的容器(android.R.id.content
)引用系统layout的root,然后覆盖整个屏幕
要解决,请使用不带 android
前缀的它们。
In
AppCompat
, there is no native support forActionBar
.android.R.id.content
is the container of entire app screen. This means - includingActionBar
, becauseActionBar
is emulated there and added as a standard view hierarchy.
您可能想使用(在 Layout
中):
android:id="@+id/content"
和(在Java
):
getSupportFragmentManager().beginTransaction().add(R.id.content, fragment,
UserCheckinsFragment.class.getName()).commit();
那么,它应该可以工作。
您好,我遇到了同样的问题,我通过将 "app:layout_behavior="@string/appbar_scrolling_view_behavior"" 添加到我的线性布局并包含 RecylerView 布局的布局父级中来修复它,现在它可以正常工作但是我还有一个问题,页面底部的按钮消失了