我有一个简单的布局是CoordinatorLayout
包含Toolbar
在AppBarLayout
和RecyclerView
。为了在内容加载到RecyclerView
时允许进度条,我将其包装在一个FrameLayout
中,旁边还有一个ProgressBar
,这是我从另一个文件中包含的。当内容被加载时,ProgressBar
被设置为VISIBLE
,并且当它完成时,它被设置为GONE
,显示RecyclerView
。我想使用ScrollingViewBehavior
,这样当我滚动我的RecyclerView
时,隐藏了Toolbar
。我试过把它添加到FrameLayout
和RecyclerView
,似乎都没有工作。Android CoordinatorLayout行为与复杂的布局
我需要做些什么来获得我正在寻找的行为?我是否需要制作新的ViewGroup
或类似的东西才能显示/隐藏ProgressBar
并为此定义新的Behavior
,还是有更简单的方法?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme"
android:background="?attr/colorPrimary"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:id="@+id/recycler_view" />
<include layout="@layout/progress_circle" />
</FrameLayout>
<include layout="@layout/floating_action_button"/>
</android.support.design.widget.CoordinatorLayout>
哦,这是有道理的,因为'CoordinatorLayout'基本上只是一个'FrameLayout'。我会尝试一下并回复你。 – mrobinson7627
完全作品,谢谢! – mrobinson7627