1

I'm trying to show a "checkout" button at the bottom of the page under my RecyclerView.

My XML file looks like this:

<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light"
    android:id="@+id/drawer_layout"
    tools:context=".Cart">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            layout="@layout/main_toolbar"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Cart"
            android:gravity="center"
            android:fontFamily="@font/poppinsbold"
            android:textSize="20dp"
            android:textStyle="bold"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="10dp"/>


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="555dp"
            android:layout_marginBottom="500px"/>
        

        <Button
            android:id="@+id/checkout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Checkout" />

    </LinearLayout>


    <RelativeLayout

        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white">


        <include
            layout="@layout/main_nav_drawer"/>
    </RelativeLayout>

</androidx.drawerlayout.widget.DrawerLayout>

Unfortunately, when I apply the changes, the products look great, but the button doesn't show.

How can I make it shows up?

Many thanks in advance.

Zain
  • 37,492
  • 7
  • 60
  • 84
Koti
  • 177
  • 11

3 Answers3

1

Problem is with your layout_marginBottom attribute of RecyclerView. 500px?! Are you kidding me? 8dp will be enough.

AliAndArdDev
  • 181
  • 1
  • 8
1

Potential Options:

1

You need to

  • Remove the bottom padding of the RecyclerView
  • Not to designate the height of the RecyclerView, and instead use a weight of the RecyclerView to be expanded until the button
  • Remove android:layout_alignParentBottom="true" from the Button as it's not related to the LinearLayout

Applying that:

<?xml version="1.0" encoding="utf-8"?>

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/main_toolbar" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="20dp"
            android:fontFamily="@font/poppinsbold"
            android:gravity="center"
            android:text="@string/Cart"
            android:textSize="20dp"
            android:textStyle="bold" />


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp" />
    
        <Button
            android:id="@+id/checkout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Checkout" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white">

        <include layout="@layout/main_nav_drawer" />
        
    </RelativeLayout>

</androidx.drawerlayout.widget.DrawerLayout>
Zain
  • 37,492
  • 7
  • 60
  • 84
  • 1
    Many thanks for the answer Zain. It actually solved my problem and I'll work on it in to make the layout exactly as I want to. – Koti Apr 24 '21 at 19:40