Nabla Iluig Ed Nabla Iluig Ed - 6 months ago 29
Android Question

Android Layout Help: 2 textview vertical Inline next to 1 button

I try to do this layout but i got only echec until now:
- 2 textview vertical Align sharing 50% width with 1 button.
- all must be vertical centered.

Here is the mockup showing what i want:

Mockup

Here is my actual code :

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/PanelName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="@color/colorBlack"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Parking Name"
android:textSize="14sp" />

<TextView
android:id="@+id/PanelAddress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="@color/colorBlack"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Parking Address blablabla Paris"
android:textSize="14sp" />

</LinearLayout>


<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_go"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:textColor="@color/colorAccent"
android:layout_marginTop="30dp"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
android:padding="12dp"
android:text="GO !"/>

</LinearLayout>


Thanks for help :)

Answer

Remove Nested Linear Layouts it's bad for performance. I have made some changes in your Layout. Make your AppCompatButton Layout inside Relative Layout and make it's width to android:layout_width="wrap_content" and also Remove First Linear Layout inside Root Layout.

Refer this.

<?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"
    android:id="@+id/image_area"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/btn_go"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/PanelName"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:text="Parking Name"
            android:textColor="#000"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/PanelAddress"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:text="Parking Address blablabla Paris Parking Address blablabla Paris Parking Address blablabla Paris"
            android:textColor="#000"
            android:textSize="14sp" />

    </LinearLayout>


    <android.support.v7.widget.AppCompatButton
        android:id="@+id/btn_go"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="24dp"
        android:layout_marginRight="24dp"
        android:layout_marginTop="30dp"
        android:layout_weight="2"
        android:background="#000"
        android:padding="12dp"
        android:text="GO !"
        android:textColor="#FFF" />

</RelativeLayout>

Here is Screen.

enter image description here