CoordinatorLayout 中工具栏下方的进度条
Progressbar below Toolbar in CoordinatorLayout
我有这样的布局 XMl :
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<RelativeLayout/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<RecyclerView/>
</CoordinatorLayout>
我想在工具栏下方和回收站视图上方添加一个水平进度条,以指示回收站视图项目的数据加载。
使用相对布局,我可以简单地为操作栏下方的进度条提供 android:layout_below 属性。但作为 Coordinator Layout 和 Toolbar 的新手,我无法得到结果。
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<RelativeLayout/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<LinearLayout>
<ProgressBar>
<RecyclerView/>
</LinearLayout>
</CoordinatorLayout>
以上内容应该可以满足您的需求。确保线性布局上的方向是垂直的。唯一需要注意的是,如果你的回收站视图很大,你可能需要将线性布局包裹在一个嵌套滚动视图中,假设你也希望进度条也能滚动。
如果你想用 Toolbar
隐藏 ProgressBar
将 Toolbar
包裹在 LinearLayout
中并将 ProgressBar
作为第一个 child LinearLayout
。分配
orientation="vertical"
如果您希望 ProgressBar
始终可见,请将 RecyclerView
包裹在 LinearLayout
内,并将 ProgressBar
作为第一个 child。设置方向。记得加
app:layout_behavior="@string/appbar_scrolling_view_behavior"
作为LinearLayout
的参数(它必须将滚动传递给child)
将 ProgressBar 作为 CoordinatorLayout 的直接子项。
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView>
</NestedScrollView>
<ProgressBar/>
<BottomAppBar/>
<FloatingActionButton/>
</CoordinatorLayout>
对于 ProgressBar,使用 layout_anchor 并将其锚定到 AppBarLayout(等于 AppBarLayout id)。将 layout_anchorGravity 设置为底部。
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="@{viewModel.loading ? View.VISIBLE : View.GONE}"
app:layout_anchor="@id/appBarLayout"
app:layout_anchorGravity="bottom" />
我附上代码和预览截图。
我有这样的布局 XMl :
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<RelativeLayout/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<RecyclerView/>
</CoordinatorLayout>
我想在工具栏下方和回收站视图上方添加一个水平进度条,以指示回收站视图项目的数据加载。
使用相对布局,我可以简单地为操作栏下方的进度条提供 android:layout_below 属性。但作为 Coordinator Layout 和 Toolbar 的新手,我无法得到结果。
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<RelativeLayout/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<LinearLayout>
<ProgressBar>
<RecyclerView/>
</LinearLayout>
</CoordinatorLayout>
以上内容应该可以满足您的需求。确保线性布局上的方向是垂直的。唯一需要注意的是,如果你的回收站视图很大,你可能需要将线性布局包裹在一个嵌套滚动视图中,假设你也希望进度条也能滚动。
如果你想用 Toolbar
隐藏 ProgressBar
将 Toolbar
包裹在 LinearLayout
中并将 ProgressBar
作为第一个 child LinearLayout
。分配
orientation="vertical"
如果您希望 ProgressBar
始终可见,请将 RecyclerView
包裹在 LinearLayout
内,并将 ProgressBar
作为第一个 child。设置方向。记得加
app:layout_behavior="@string/appbar_scrolling_view_behavior"
作为LinearLayout
的参数(它必须将滚动传递给child)
将 ProgressBar 作为 CoordinatorLayout 的直接子项。
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView>
</NestedScrollView>
<ProgressBar/>
<BottomAppBar/>
<FloatingActionButton/>
</CoordinatorLayout>
对于 ProgressBar,使用 layout_anchor 并将其锚定到 AppBarLayout(等于 AppBarLayout id)。将 layout_anchorGravity 设置为底部。
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="@{viewModel.loading ? View.VISIBLE : View.GONE}"
app:layout_anchor="@id/appBarLayout"
app:layout_anchorGravity="bottom" />
我附上代码和预览截图。