0

This is my working xml code.. Now I want to add two text view and one button below the listview without changing the height of the list view.

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearlayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ListView
            android:id="@+id/orderlist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:divider="#778899"
            android:dividerHeight="1dp" >
        </ListView>

        <LinearLayout
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical" >

            <include layout="@layout/footer" />
        </LinearLayout>

    </RelativeLayout>
yamuna
  • 41
  • 1
  • 9

5 Answers5

1

This is working at my end .try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        >

        <TextView
            android:id="@+id/first"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:textColor="@android:color/white"
            android:background="@android:color/background_dark"
            android:text="First Text" />

        <TextView
            android:id="@+id/sec"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_below="@id/first"
            android:textColor="@android:color/white"
            android:background="@android:color/background_dark"
            android:text="First Text" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/sec"
            android:text="First Text" />
    </RelativeLayout>

    <ListView
        android:id="@+id/orderlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/layout"
        android:layout_alignParentLeft="true"
        android:divider="#778899"
        android:dividerHeight="1dp" >
    </ListView>

</RelativeLayout>
Varun garg
  • 81
  • 2
0

Change your listview and added android:layout_above="@+id/layout" in listview controll

<ListView
            android:id="@+id/orderlist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/layout"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:divider="#778899"
            android:dividerHeight="1dp" >

        </ListView>
Piyush
  • 18,895
  • 5
  • 32
  • 63
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
0

Change listview as below

    <ListView
        android:id="@+id/orderlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:divider="#778899"
        android:layout_above="@id/layout"
        android:dividerHeight="1dp" >
    </ListView>
MathanG
  • 1,195
  • 10
  • 22
0

Add the android:layout_above="@+id/layout" in list view.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ListView
    android:id="@+id/orderlist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/layout"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:divider="#778899"
    android:dividerHeight="1dp" >
</ListView>

<LinearLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Total Price : 20.00"
        android:textColor="@android:color/black"
        android:textSize="16sp" >
    </TextView>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Buy" />

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/footer" />
</LinearLayout>

</RelativeLayout>
Yugesh
  • 4,030
  • 9
  • 57
  • 97
0

What you can also do in this case is define the parameter layout_weight of your componentes according to your needs.

What does layout weight means?

Community
  • 1
  • 1
VulfCompressor
  • 1,390
  • 1
  • 11
  • 26