Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add RelativeLayout with buttons below RecyclerView

I need to add a RelativeLayout below my RecyclerView and was able to do so, except that the button under TOTAL(R.id.total_amount_tv) does not show:

enter image description here

I can easily scroll through the items and it doesn't affect my RelativeLayout. I just need the button to be visible.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:weightSum="1">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/order_recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="40dp"
        tools:context=".ShoppingCartActivity" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp">

        <TextView
            android:id="@+id/total_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:text="@string/total"
            android:textSize="20sp"
            android:textStyle="bold|italic" />

        <TextView
            android:id="@+id/total_amount_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/total_tv"
            android:textSize="20sp"
            android:textStyle="bold|italic" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/total_amount_tv"
            android:layout_marginTop="51dp"
            android:background="@color/accent"
            android:onClick="onClickSendOrder"
            android:text="@string/order_btn"
            android:textColor="@android:color/white"
            android:textSize="20sp" />
    </RelativeLayout>

</RelativeLayout>
like image 367
Helenesh Avatar asked Sep 12 '16 15:09

Helenesh


People also ask

How to add button in RecyclerView in android?

Build a Load More Button into a recyclerview. The first thing to do is to create a layout with your button and modify your viewhold to get the button id: Then a simple way to make a button is to add +1 to the getItemCount() and a flag (i.e. boolean) to know if you need to draw the button.

What is a Relative layout in android?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).


2 Answers

android:layout_alignParentBottom="true"

This is the likely culprit. Both TextViews are aligned at the bottom of their parent RelativeLayout. This doesn't leave room for the Button.

like image 68
Code-Apprentice Avatar answered Oct 13 '22 22:10

Code-Apprentice


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/downline_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/lin_result"
        android:layout_marginTop="5dp" />

    <LinearLayout
        android:id="@+id/lin_result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#f8ffffff"
        android:orientation="vertical"
        android:paddingBottom="10dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_marginBottom="5dp"
            android:background="#999898" />

        <TextView
            android:id="@+id/text_total_rupees"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:paddingLeft="10dp"
            android:text="100" 
         android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
       </LinearLayout>
    </RelativeLayout>  
like image 45
Ashish Avatar answered Oct 13 '22 23:10

Ashish