【解疑答惑】—— android:maxLines="1"没满一行显示省略号,用android:singleLine="true"解决

带标签的文本
数据

  1. android:maxLines=”1”, 还没满一行就会会显示省略号
    显示省略号

  2. android:singleLine=”true”, 正常显示
    正常显示

问题原因:

Google Document 的解释:

android:maxLines
Makes the TextView be at most this many lines tall.

android:singleLine
Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key.
55

具体区别:

   android:maxLines是限制高度,android:singleLine是强制不让换行。从高度上来讲二者是一样的,都只显示了一行字串, 但从换行的角度来讲,android:maxLines并不会改变换行的位置,而android:singleLine则会改变换行的位置。所以,如果要截取字符串并追加省略号显示,尽量用android:singleLine属性。如果要控制显示行数,尽量用android:maxLines属性。
优化此布局<com.google.android.material.textfield.TextInputLayout android:id="@+id/usernameLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:hint="用户名" layout_height="" layout_width="" xmlns:android="http://schemas.android.com/apk/res/android"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/usernameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" android:maxLines="1" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/passwordLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="密码"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/passwordEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:maxLines="1" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/phoneLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:hint="密码"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/phoneEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:maxLines="1" /> </com.google.android.material.textfield.TextInputLayout> <Button android:id="@+id/registerButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="注册" /> </com.google.android.material.textfield.TextInputLayout>
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值