【问题标题】:android:singleLine of TextView is nolonger in the "Deprecated"?android:singleLine 的 TextView 不再在“已弃用”中?
【发布时间】: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:scrollHorizo​​ntally="true" 并没有反映在 xml 文件中。

所以,我尝试使用 setHorizo​​ntallyScrolling 方法,它奏效了。

*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:scrollHorizo​​ntally="true",我也使用 android:lines 代替 android:maxLines,但是没有用。

标签: android textview deprecated


【解决方案1】:

也尝试将 IME 输入设置为短文本或类似内容。它可能会起作用。 elipsize 有很多问题,我当时也遇到过,但没能解决。就我而言,它主要连接到editTexts,而其他组件则将焦点从视图中移开。 Elipsize 需要专注才能发挥作用。

【讨论】:

  • 好吧,不幸的是,如果有什么东西让你失去焦点,我认为你不会。顺便说一句,我一直假设你想用它来实现选框效果。我记得有一些例子是人们使用动画来做这个椭圆。
  • 试试这两个链接,看看它们的链接:stackoverflow.com/questions/2160619/…, stackoverflow.com/questions/1827751/…
  • 感谢 DArkO。我解决了这个问题。 xml 文件中描述的 android:scrollHorizo​​ntally="true" 不反映。相反,我使用“setHorizo​​ntallyScrolling”方法,确实有效。谢谢!
【解决方案2】:

我不确定TextView的android:singleLine是否不再在“Deprecated”中,因为在TextView的deprecated构造函数中,有一条关于singleLine配置的注释..

// 如果设置,输入类型将覆盖使用已弃用的 singleLine 标志设置的内容。

singleLine = !isMultilineInputType(inputType);

源码:core/java/android/widget/TextView.java - platform/frameworks/base - Git at Google的1156L左右

由于 Google 发表评论说不推荐使用 singleLine 标志,(尽管它没有写在开发者网站上)它可能是这样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    • 2021-07-26
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    • 2022-07-10
    • 1970-01-01
    相关资源
    最近更新 更多