Search code examples
androidspace

Facing trouble in adding space


I want to add separator between 'TextView's. Two 'Space's are there, the last one works fine, but the first one takes large space horizontally. I am attaching a screenshot. I don't understand what is causing the problem. Can any one say what is happening there. Thanks in advance.

<TableLayout
    android:id="@+id/tl_search"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="10dp"
    android:paddingEnd="10dp">
    <TableRow>
        <EditText
            android:id="@+id/et_search"
            android:layout_column="0"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:hint="Type here"/>
        <ImageButton
            android:id="@+id/ib_search"
            android:layout_column="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_search"
            android:contentDescription="Search image"/>
    </TableRow>
    <TableRow android:orientation="vertical">
        <TextView
            android:id="@+id/btn_previous"
            android:layout_column="0"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Previous"
            android:padding="5dp"
            android:background="#0d0f21"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:textSize="15sp"/>
        <Space
            android:layout_width="1dp"
            android:layout_height="match_parent"/>
        <TextView
            android:id="@+id/btn_clear"
            android:layout_column="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Clear"
            android:padding="5dp"
            android:background="#0d0f21"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:textSize="15sp"/>
        <Space
            android:layout_width="1dp"
            android:layout_height="match_parent"/>
        <TextView
            android:id="@+id/btn_search"
            android:layout_column="2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:padding="5dp"
            android:background="#0d0f21"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:textSize="15sp"/>
    </TableRow>

</TableLayout>

Screenshot


Solution

  • Give android:layout_column="1" in your Textview id android:id="@+id/btn_previous" and your issue will be solved

    Try this

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff"
        android:orientation="vertical">
    
    
        <TableLayout
            android:id="@+id/tl_search"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingEnd="10dp"
            android:paddingStart="10dp">
    
            <TableRow>
    
                <EditText
                    android:id="@+id/et_search"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_column="0"
                    android:layout_weight="1"
                    android:hint="Type here" />
    
                <ImageButton
                    android:id="@+id/ib_search"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:contentDescription="Search image"
                    android:src="@drawable/ic_add_black_24dp" />
            </TableRow>
    
            <TableRow android:orientation="vertical">
    
                <TextView
                    android:id="@+id/btn_previous"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:background="#0d0f21"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Previous"
                    android:textColor="@android:color/white"
                    android:textSize="15sp" />
    
                <Space
                    android:layout_width="1dp"
                    android:layout_height="match_parent" />
    
                <TextView
                    android:id="@+id/btn_clear"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:background="#0d0f21"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Clear"
                    android:textColor="@android:color/white"
                    android:textSize="15sp" />
    
                <Space
                    android:layout_width="1dp"
                    android:layout_height="match_parent" />
    
                <TextView
                    android:id="@+id/btn_search"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:layout_weight="1"
                    android:background="#0d0f21"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Search"
                    android:textColor="@android:color/white"
                    android:textSize="15sp" />
            </TableRow>
    
        </TableLayout>
    
    
    </LinearLayout>
    

    OUTPUT

    enter image description here