Darksymphony
Darksymphony

Reputation: 2713

Android - ImageView below recyclerView sticked to bottom

I have a RelativeLayout, inside one image on top, below Recyclerview, and below the Recyclerview I want to have an ImageView, but aligned to the bottom of the screen.

<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>

However, the image at the bottom appears only when there are no items in Recyclerview, otherwise the Image is not showing, the list is scrolling to the bottom of screen.

Upvotes: 0

Views: 30

Answers (1)

Darksymphony
Darksymphony

Reputation: 2713

Ok, solved it by adding a LinearLayput wrapper to recyclerview and adding some bottom margin.

<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>

Upvotes: 0

Related Questions