android - 如何在 CoordinatorLayout 中垂直排列的其他两个视图之间放置一个视图?
问题描述
我有一个布局文件,我在其中使用 aCollapsingToolbarLayout
和 aRecyclerView
并且工作正常。现在我试图ConstraintLayout
在 myAppBarLayout
和RecylerView
. 这是我到目前为止所尝试的:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="272dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/collapsing_toolbar_layout"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Some views-->
</RelativeLayout>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Some views-->
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/beers_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
问题是,即使我将它放在AppBarLayout
和之间,它仍然位于活动的底部RecylerView
。谁能帮我ConstraintLayout
在他们之间放置视图?谢谢
解决方案
你为什么不试试把你的RecyclerView
放进去ConstraintLayout
?
下面CollapsingToolbarLayout
:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Your views here with constraints-->
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="your last view"
/>
</ConstraintLayout>
推荐阅读
- android-studio - 在 Android Studio 中,“Layout Captures”工具有什么用
- python - 如何将关键字附加到 JPG 图像中的 IPTC 数据?
- html - 我想在 ng-repeat 循环中绑定动态计数值?
- laravel - 如何在 Laravel 的对象变量中获取随机行?
- javascript - 使用 Angular 创建可缩放的树形网页
- angular - 如何在自定义验证器中使用可注入服务
- javascript - 根据另一个自定义数组对数组中的对象属性进行排序
- google-apps-script - 基于 Google Sheet 电子表格的触发器停止工作
- java - 如何检查firebase中是否存在值
- java - 通过迭代数组并将每个元素除以从 1 开始的数字来找到最小值