Search code examples
androidxmllistviewandroid-linearlayout

Add LinearLayout below listView


I trying to add a LinearLayout under the listView but it has a space between ListView and the LinearLayout.How to remove it ? Thanks a lot.

<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="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <ImageView
        android:src="@drawable/expenses"
        android:layout_marginTop="50dp"
        android:layout_width="130dp"
        android:layout_height="210dp"
        android:id="@+id/imageView"
        android:gravity="center"
        android:layout_centerHorizontal="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:text="You haven't added any expenses yet"
        android:textSize="15dp"
        android:textColor="@color/btn_login"
        android:gravity="center"
        android:id="@+id/NoData"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/imageView"/>

    <Button
        android:layout_width="250dp"
        android:layout_height="60dp"
        android:text="Add Expenses"
        android:id="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/NoData"/>

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

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/listview"
            android:footerDividersEnabled="false"
            android:layout_weight="1"
            android:layout_alignParentBottom="true" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:background="@color/light_gray"
            android:orientation="horizontal"
            android:id="@+id/linearLayout"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

            <TextView
                android:layout_marginLeft="100dp"
                android:id="@+id/Remaining"
                android:paddingTop="10dp"
                android:textSize="20sp"
                android:layout_width="90dp"
                android:layout_height="40dp"
                android:text="Balance : " />

            <TextView
                android:layout_marginLeft="10dp"
                android:id="@+id/balance"
                android:paddingTop="10dp"
                android:textSize="20sp"
                android:layout_width="79dp"
                android:layout_height="40dp"
                android:text="balance " />
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

Below show my image

enter image description here


Solution

  • You need to remove this attribute android:paddingBottom="@dimen/activity_vertical_margin"

    so it should look like this

    <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="match_parent"
        tools:context=".MainActivity">
    

    paddingBottom will place a gap between your parent relative layout and the bottom of the screen