How can I make the TextView controls which contain characters "A" have the same width with text align left and control align right?

HelloCW

I hope the TextView controls which contain characters "A" have the same width with text align left and control align right , so I have set TextView controls which contain characters "A" with max width="150dp", and I have set android:gravity="left" and android:layout_gravity="right"

I think I can get the result AA.png, but in fact the result is BB.png

I hope (AA.png)

enter image description here

Current (BB.png)

enter image description here

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/border_ui"
    android:orientation="vertical" >

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        android:layout_alignParentTop="true"
        ads:adUnitId="@string/ad_unit_id" />


    <LinearLayout
        android:layout_above="@+id/linearLayout1"
        android:layout_below="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:layout_gravity="right"
            android:layout_weight="0.5">

            <TextView
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="A"
                android:id="@+id/textView2"/>

            <TextView
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="AAA"
                android:id="@+id/textView4"/>

            <TextView
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="AAAAA"
                android:id="@+id/textView5"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="B"
                android:id="@+id/textView3"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="BBB"
                android:id="@+id/textView6"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="BBBB"
                android:id="@+id/textView7"/>
        </LinearLayout>
    </LinearLayout>





    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:weightSum="4" >

        <Button
            android:id="@+id/btnReturn"
            style="@style/myTextMedium"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:text="@string/BtnReturn" />
    </LinearLayout>

</RelativeLayout>
jmateo

You can accomplish that by adding an extra LinearLayout and removing the 150dp limitation:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    android:layout_alignParentTop="true"
    ads:adUnitId="@string/ad_unit_id" />


<LinearLayout
    android:layout_above="@+id/linearLayout1"
    android:layout_below="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:layout_weight="0.5">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="right">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="A"
            android:id="@+id/textView2"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="AAA"
            android:id="@+id/textView4"/>

        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="AAAAA"
            android:id="@+id/textView5"/>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="B"
            android:id="@+id/textView3"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="BBB"
            android:id="@+id/textView6"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="BBBB"
            android:id="@+id/textView7"/>
    </LinearLayout>
</LinearLayout>





<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"
    android:weightSum="4" >

    <Button
        android:id="@+id/btnReturn"
        style="@style/myTextMedium"
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:text="@string/BtnReturn" />
</LinearLayout>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How may I align text to the left and text to the right in the same line?

How do I make a text at both left and right align?

How can I left and right align text to center?

How can I left align text in a TextButton?

Left and Right align text on the same line

Align text to the left and right on the same line with CSS

flutter ListView - How do I align left and right at the same time?

Having some text align left and other align right, in same line

In CSS how can I make an element with "position: absolute" align left but also be contained right?

How can I align two different-size pieces of text to the left and right while matching baselines?

How can I align text both left and right in a C# WinForms button?

How to align results left and right at the same time

How to align button left and right in the same line?

How to align icon to left and text to the right of it

How to align (an ImageView and a TextView) to the left and (an ImageView and a TextView) to the right

How can I align my Label text on the left and still have X-axis scroll in Kivy?

Align text to right of upper text (which is aligned to left). Widths unknown

How can I get some buttons to align-left and some to align-right inside a DIV?

How to align controls left and top without fixed width?

How can I make Bootstrap components align right?

Left align text AND right align image in CSS

Right align text in android TextView

How can I make the left div expand and the right div have constant width?

Apache POI, align text to left and other text to right in same row

How can I right align column with text and input?

How can I align checkbox with text to right side of the screen?

How can i align span text left inside <td>?

How can I left-align text in bootstrap link button?

How I can align the header text of the ExpandableListview to the extreme left?