我怎样才能使含有字符&QUOT TextView的控制; A"已经离开文本对齐相同的宽度和控制右对齐?能使、宽度、字符、文本

2023-09-07 00:18:42 作者:℡世界這麼混

我希望它含有字符A都与文本对齐相同的宽度左,控制右对齐TextView的控制,所以我已经设置包含字符A,最大宽度=150dpTextView的控制,我已经设定安卓重力=左的android:layout_gravity =正确的

我想我可以得到的结果AA.png,但实际上结果是BB.png

我希望(AA.png)

电流(BB.png)

 <?XML版本=1.0编码=UTF-8&GT?;<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android    机器人:layout_width =FILL_PARENT    机器人:layout_height =FILL_PARENT    机器人:背景=@绘制/ border_ui    机器人:方向=垂直>    < com.google.android.gms.ads.AdView        的xmlns:广告=htt​​p://schemas.android.com/apk/res-auto        机器人:ID =@ + ID / AD浏览        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        广告:adSize时=SMART_BANNER        机器人:layout_alignParentTop =真        广告:adUnitId设置=@字符串/ AD_UNIT_ID/>    <的LinearLayout        机器人:layout_above =@ + ID / linearLayout1        机器人:layout_below =@ + ID / AD浏览        机器人:layout_width =match_parent        机器人:layout_height =match_parent        机器人:方向=横向        >        <的LinearLayout            机器人:方向=垂直            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:重力=左            机器人:layout_gravity =右            机器人:layout_weight =0.5>            <的TextView                机器人:layout_width =150dp                机器人:layout_height =WRAP_CONTENT                机器人:textAppearance =机器人:ATTR / textAppearanceMedium                机器人:文字=A                机器人:ID =@ + ID / textView2/>            <的TextView                机器人:layout_width =150dp                机器人:layout_height =WRAP_CONTENT                机器人:textAppearance =机器人:ATTR / textAppearanceMedium                机器人:文字=AAA                机器人:ID =@ + ID / textView4/>            <的TextView                机器人:layout_width =150dp                机器人:layout_height =WRAP_CONTENT                机器人:textAppearance =机器人:ATTR / textAppearanceMedium                机器人:文字=AAAAA                机器人:ID =@ + ID / textView5/>        < / LinearLayout中>        <的LinearLayout            机器人:方向=垂直            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:layout_weight =0.5>            <的TextView                机器人:layout_width =WRAP_CONTENT                机器人:layout_height =WRAP_CONTENT                机器人:textAppearance =机器人:ATTR / textAppearanceMedium                机器人:文字=B                机器人:ID =@ + ID / textView3/>            <的TextView                机器人:layout_width =WRAP_CONTENT                机器人:layout_height =WRAP_CONTENT                机器人:textAppearance =机器人:ATTR / textAppearanceMedium                机器人:文字=BBB                机器人:ID =@ + ID / textView6/>            <的TextView                机器人:layout_width =WRAP_CONTENT                机器人:layout_height =WRAP_CONTENT                机器人:textAppearance =机器人:ATTR / textAppearanceMedium                机器人:文字=BBBB                机器人:ID =@ + ID / textView7/>        < / LinearLayout中>    < / LinearLayout中>    <的LinearLayout        机器人:ID =@ + ID / linearLayout1        机器人:layout_width =FILL_PARENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_gravity =center_vertical        机器人:比重=中心        机器人:方向=横向        机器人:layout_alignParentBottom =真        机器人:weightSum =4>        <按钮            机器人:ID =@ + ID / btnReturn            风格=@风格/ myTextMedium            机器人:layout_width =0dip            机器人:layout_height =FILL_PARENT            机器人:layout_gravity =中心            机器人:layout_weight =1            机器人:文字=@字符串/ BtnReturn/>    < / LinearLayout中>< / RelativeLayout的> 

解决方案

您可以通过增加一个额外的LinearLayout和取出150dp限制,实现这一目标:

      

 < com.google.android.gms.ads.AdView    的xmlns:广告=htt​​p://schemas.android.com/apk/res-auto    机器人:ID =@ + ID / AD浏览    机器人:layout_width =WRAP_CONTENT    机器人:layout_height =WRAP_CONTENT    广告:adSize时=SMART_BANNER    机器人:layout_alignParentTop =真    广告:adUnitId设置=@字符串/ AD_UNIT_ID/><的LinearLayout    机器人:layout_above =@ + ID / linearLayout1    机器人:layout_below =@ + ID / AD浏览    机器人:layout_width =match_parent    机器人:layout_height =match_parent    机器人:方向=横向    >    <的LinearLayout        机器人:方向=垂直        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:重力=左        机器人:layout_weight =0.5>        <的LinearLayout            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:方向=垂直            机器人:layout_gravity =右>        <的TextView            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:textAppearance =机器人:ATTR / textAppearanceMedium            机器人:文字=A            机器人:ID =@ + ID / textView2/>        <的TextView            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:textAppearance =机器人:ATTR / textAppearanceMedium            机器人:文字=AAA            机器人:ID =@ + ID / textView4/>        <的TextView            机器人:layout_width =150dp            机器人:layout_height =WRAP_CONTENT            机器人:textAppearance =机器人:ATTR / textAppearanceMedium            机器人:文字=AAAAA            机器人:ID =@ + ID / textView5/>        < / LinearLayout中>    < / LinearLayout中>    <的LinearLayout        机器人:方向=垂直        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_weight =0.5>        <的TextView            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:textAppearance =机器人:ATTR / textAppearanceMedium            机器人:文字=B            机器人:ID =@ + ID / textView3/>        <的TextView            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:textAppearance =机器人:ATTR / textAppearanceMedium            机器人:文字=BBB            机器人:ID =@ + ID / textView6/>        <的TextView            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:textAppearance =机器人:ATTR / textAppearanceMedium            机器人:文字=BBBB            机器人:ID =@ + ID / textView7/>    < / LinearLayout中>< / LinearLayout中><的LinearLayout    机器人:ID =@ + ID / linearLayout1    机器人:layout_width =FILL_PARENT    机器人:layout_height =WRAP_CONTENT    机器人:layout_gravity =center_vertical    机器人:比重=中心    机器人:方向=横向    机器人:layout_alignParentBottom =真    机器人:weightSum =4>    <按钮        机器人:ID =@ + ID / btnReturn        风格=@风格/ myTextMedium        机器人:layout_width =0dip        机器人:layout_height =FILL_PARENT        机器人:layout_gravity =中心        机器人:layout_weight =1        机器人:文字=@字符串/ BtnReturn/>< / LinearLayout中> 
Android02之TextView和Button

    

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)

Current (BB.png)

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

解决方案

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>