vimal mishra
vimal mishra

Reputation: 1167

How to add button between listview?

I am trying to put button between two list view which are vertically aligned.Can someone please help me out with the problem.I am very new to android ,I don't have any idea how to do that.

I want to put two small button in the space available between two columns.Please find the below xml code :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.edkul.vimal.edkul.Library"
    android:id="@+id/linearLayout1"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/library"
        android:textSize="25sp"
        android:id="@+id/textView27"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />


    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="35dp"
        android:layout_below="@+id/textView27">
        <ListView
            android:id="@+id/list_item1"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_marginRight="55dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:background="#88FF0000">
        </ListView>
        <ListView
            android:id="@+id/list_item3"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:background="#88FF0000">
        </ListView>
    </LinearLayout>
    <Button
        android:layout_width="match_parent"
        android:layout_below="@+id/linearLayout2"
        android:layout_height="match_parent"
        android:text="Button1"/>

</RelativeLayout>

Please find the below image as a reference.

Upvotes: 0

Views: 92

Answers (2)

Jay Rathod
Jay Rathod

Reputation: 11255

Try with this.

Replace this full code in your XML.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.edkul.vimal.edkul.Library">

    <TextView
        android:id="@+id/textView27"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="Library"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="25sp" />


    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView27"
        android:layout_marginTop="35dp"
        android:orientation="horizontal"
        android:weightSum="2">

        <ListView
            android:id="@+id/list_item1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="1"
            android:background="#88FF0000"></ListView>

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:orientation="vertical"
            android:weightSum="2">

            <Button
                android:id="@+id/btn1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Button1" />

            <Button
                android:id="@+id/btn2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Button1" />
        </LinearLayout>

        <ListView
            android:id="@+id/list_item3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="1"
            android:background="#88FF0000"></ListView>
    </LinearLayout>


</RelativeLayout>

It will show you button exactly between your listviews.

Surely it will help you.

Upvotes: 2

VarunJoshi129
VarunJoshi129

Reputation: 4852

Make the layout orientation as horizontal .use your first list views and button as 3views in your layout . Make height as match parent for listviews but wrap content for button . Check if it works

Upvotes: 0

Related Questions