How can I make the width of the TextView control containing the character "A" the same as the width of the text left-aligned and the control right-aligned?


HelloCW

I want the control "A" of the TextView that contains the characters to be the same width as the text left aligned and the control right aligned, so I have a TextView control that contains the characters "A" with max-width="150dp" and I have set it android:gravity="left"withandroid:layout_gravity="right"

I thought I could get the result AA.png, but actually the result is BB.png

I hope (AA.png)

enter image description here

Currently (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>
Jiemeitu

You can do this by adding an extra LinearLayout and removing the 150dp limit:

<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>

Related


How to make text aligned with block but left aligned?

LKG I wish to use css flex property( "image content" text center aligned to block but left aligned) like the image below. but i got this .wrapper { max-width:300px; } .main { width:300px; display:flex; justify-content:center; align-items:center; fl

How to adjust the width of a right-aligned navbar

Asparagine Link to jsfiddle : https://jsfiddle.net/ckmmd5aL/ Here is my bootstrap HTML <div class="img-full"> <div class="container"> <nav class="navbar navbar-default"> <div class="container-fluid"> <div

How to adjust the width of a right-aligned navbar

Asparagine Link to jsfiddle : https://jsfiddle.net/ckmmd5aL/ Here is my bootstrap HTML <div class="img-full"> <div class="container"> <nav class="navbar navbar-default"> <div class="container-fluid"> <div

R: fixed width aligned left

randomize I am trying to save a to a file data.framethis way : library(gdata) write.fwf(mydata,file = "myfile.txt",width = c(12, 7), eol="\r\n", colnames = FALSE, justify = "left") The data is very simple: V1 V2 1 foo 2 bar 3 ter 4 four However, the

How can I make each character the same width?

Hao Wu I am using a custom font. The design doesn't allow me to change the font. When the number changes, its content is pushed due to the different width of the number. Is there a way to make all numbers have the same width? I don't want to assign the width o

How can I make each character the same width?

Hao Wu I am using a custom font. The design doesn't allow me to change the font. When the number changes, its content is pushed due to the different width of the number. Is there a way to make all numbers have the same width? I don't want to assign the width o