显示在AppBarLayout上方的FrameLayout [英] FrameLayout Shown Above AppBarLayout
问题描述
我有一个带有AppBarLayout
和FrameLayout
的简单CoordinatorLayout
,但是无论FrameLayout
上的layout_behavior属性如何,FrameLayout
的内容都显示在AppBarLayout
上.我尝试过将该属性添加到其他位置(例如在我的RecyclerView
上),但这是相同的行为.
I have a simple CoordinatorLayout
with a AppBarLayout
and FrameLayout
, but the FrameLayout
contents are being displayed over the AppBarLayout
regardless of the layout_behavior attribute on the FrameLayout
. I've tried adding that attribute elsewhere (like on my RecyclerView
), but it's the same behavior.
下面是一张图片,显示了我的意思.
活动布局:
<?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"/>
如何在活动"中添加片段:
How I add my fragment in my 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();
推荐答案
xml中的FrameLayout
ID(@android:id/content
)和Fragment
事务中的容器(android.R.id.content
)引用系统 布局的根 ,然后将其放置在所有屏幕上.
The FrameLayout
ID (@android:id/content
) in the xml and the container (android.R.id.content
) in the Fragment
transaction refer to the system root of layout, then it is laid over the all screen.
要解决此问题,请使用不带android
前缀的
To solve, use them without android
prefix.
这篇关于显示在AppBarLayout上方的FrameLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!