techiegul
techiegul

Reputation: 11

How to align two text in extreme ends (left and right) in a Single Button View android

I have a button for showing list of items in a different popup In that button, I want a text as a label which is left aligned and a text on the right side which would be dynamically added depending on the item selected from the popup

How to align these two texts on a single button? I'm new to android.

Tried giving different ascii characters as spaces but didn't help

<Button
            android:id="@+id/button"
            android:layout_width="400dp"
            android:layout_height="80dp"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="14dp" />

Expected Result

[**Name**                    john] ---- single button view with two texts

enter image description here

Upvotes: 0

Views: 452

Answers (1)

JakeB
JakeB

Reputation: 2113

Wrap your button and textviews withhin a frame layout, along with elevation to display the textviews over the button :

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

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:textAllCaps="false"
        android:textSize="14dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
        android:text="TextView 1"
        android:layout_margin="5dp"
        android:elevation="2dp"
        android:outlineProvider="none"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|end"
        android:text="TextView 2"
        android:layout_margin="5dp"
        android:elevation="2dp"
        android:outlineProvider="none"/>

</FrameLayout>

Note: android:outlineProvider="none" will remove the shadow on the textviews that the elevation provides.

enter image description here

Upvotes: 1

Related Questions