【发布时间】:2011-10-24 23:07:05
【问题描述】:
我面临一个在 TextView 中不起作用的 android:ellipsize 问题。 但要适用于 android:singleLine。
听说 android:singleLine 已“弃用”,但在 Android Developer 的参考资料中没有写。
https://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine
android:singleLine 不再在“已弃用”中?
添加: 我自己解决了这个问题。
事实证明,TextView 的属性的 android:scrollHorizontally="true" 并没有反映在 xml 文件中。
所以,我尝试使用 setHorizontallyScrolling 方法,它奏效了。
*xml:*
<TextView
android:id="@+id/text"
android:ellipsize="end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
*code:*
TextView textView = (TextView)findViewByID(R.id.text);
textView.setHorizontallyScrolling(true);
但是,我在 xml 中添加了“android:inputType="text",如下所示,它不起作用。 请小心。
*xml:*
<TextView
android:id="@+id/text"
**android:inputType="text"**
android:ellipsize="end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
【问题讨论】:
-
对不起,ntc,我错误地删除了你的答案。我试过 android:maxLines="1",但没有用。我尝试使用 android:maxLines="1" 和 android:scrollHorizontally="true",我也使用 android:lines 代替 android:maxLines,但是没有用。
标签: android textview deprecated