android:hint属性对TextView的影响

Posted lytwajue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android:hint属性对TextView的影响相关的知识,希望对你有一定的参考价值。

近期看到同事写的一段代码,非常easy吧就是:

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="XXXXX"
            android:text="x"
           />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:text="(x)"
            />
    </LinearLayout>

显示的效果例如以下:

技术分享

是的效果就是这样,两个x之间有非常大的空隙,開始我以为是同事设置了什么,后来看了xml没看出什么。想到了以为是设置minWidth,可是也没有看到,关键是显示的效果确实有最小长度,找了半天,最后才意识到hint这个属性,设置了hint属性后,对应的TextView的最小宽度也会跟你设置的文字长度有关,这就是这个问题的终于原因,到此,我想说的结束了。。。



以上是关于android:hint属性对TextView的影响的主要内容,如果未能解决你的问题,请参考以下文章

android studio 编写时textview 和edittext无法在同一行显示

Android文本输入框EditText属性和方法说明

Android文本输入框EditText属性和方法说明

Android文本输入框EditText禁用分号

TextView 提示弄乱了 RTL 重力

Android开始之 入门