【发布时间】:2021-11-11 09:38:04
【问题描述】:
我有“activity_main”,其中使用了折叠工具栏和片段容器。在容器内部,我添加和替换了多个片段,其中一个是“activity_user_shops_list”,它是一个回收站视图。我想将 fab 与此列表片段内的屏幕右下角对齐。我找不到对齐的方法。任何帮助表示赞赏。
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:orientation="vertical"
android:gravity="center_horizontal"
android:background="#F3F3F3">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/id_appbar_layout_m"
android:layout_width="match_parent"
android:layout_height="200dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/id_collapsing_toolbar_m"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:titleCollapseMode="scale"
app:title="@string/user_name"
app:expandedTitleGravity="center_horizontal"
app:expandedTitleMarginTop="160dp"
android:background="#F3F3F3">
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/ic_launcher"
app:shapeAppearanceOverlay="@style/circleImageView"
android:layout_gravity="center"/>
<com.google.android.material.appbar.MaterialToolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/id_appbar_layout_m"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/id_fragment_container_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
fragment_user_shops_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/null_gray">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/id_recycler_view_e_shops"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/id_floating_button_e_shops"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/add_a_shop"
android:src="@drawable/ic_plus"
app:tint="@color/white"
app:maxImageSize="30dp"
app:useCompatPadding="true"/>
</RelativeLayout>
编辑:
在添加android:layout_alignParentRight="true" 和android:layout_alignParentBottom="true" 并让所有fab 父母match_parent 之后,它仍然无法正常工作。
不管我做什么结果都是一样的。结果如下(灰色区域为“fragment_user_shops_list”):
【问题讨论】:
-
试试这个问题的答案:stackoverflow.com/questions/30769080/…
-
不幸的是它没有解决问题。我看到的主要问题是“fragment_user_shops_list”与它的父级不匹配,即使我将高度更改为 match_parent。
-
尝试将父级也匹配到 RecyclerView
-
我试过了,但是晶圆厂低于屏幕底部。我认为没有办法做到这一点。
标签: android android-recyclerview floating-action-button