我有一个RelativeLayout,在顶部的一张图像内,在Recyclerview下方,在Recyclerview下方我想要一个ImageView,但与屏幕底部对齐。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview1"
android:layout_marginTop="24sp"
android:layout_below="@id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/recyclerview1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/deco"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|center"
android:layout_marginBottom="25dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"/>
</RelativeLayout>
</RelativeLayout>
但是,只有当 Recyclerview 中没有项目时才会出现底部的图像,否则图像不会显示,列表会滚动到屏幕底部。
好的,通过向 recyclerview 添加 LinearLayput 包装器并添加一些底部边距解决了这个问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rel1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo" />
<LinearLayout
android:id="@+id/wrapper"
android:layout_below="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview1"
android:layout_marginTop="24sp"
android:layout_marginBottom="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/deco"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|center"
android:layout_marginBottom="16dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"/>
</RelativeLayout>