【问题标题】:TextView only displaying the first four lines of a resource stringTextView 只显示资源字符串的前四行
【发布时间】:2012-12-02 12:04:43
【问题描述】:

我在对话框中显示一些文本时遇到问题。当用户忘记密码时,我使用“忘记密码”TextView 来显示一条消息,解释当他们输入电子邮件地址时会发生什么。布局如下:

<TextView
    android:id="@+id/forgotpasswordtextview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/forgotpassword"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/md_text_yellow"
    android:gravity="right" />

它位于&lt;LinearLayout&gt;&lt;/LinearLayout&gt; 内,具有以下属性:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/base_panel"
    android:orientation="vertical"
    android:padding="6dip" >

它从单行视图开始,然后扩展到四行视图。

在对话框构造函数中,我有一个布局说明:

    mParent = LayoutInflater.from(context).inflate(R.layout.login, null);

    setContentView(mParent, new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

我将其更改为对话框高度为 600(它有效——一个垂直拉伸的对话框),TextView 仍然只显示四行,因此它不会被其父级压碎。

这可能是什么原因造成的?

编辑:

TextView 更改为android:textAppearance="?android:attr/textAppearanceSmall" 在同一点切断字符串,显示三行。我现在想知道这是否是字符串问题而不是TextView 问题。

原来的字符串是:

Please enter your registered email and we will send you details of how to reset your password. If you do not know your email then please contact us.

它在以下位置切断:

Please enter your registered email and we will send you details of how to reset your password. If you do not

带有小文本(三行)和

Please enter your registered email and we will send you details of how to reset your password. If you do not know

中等文本(四行)。

我输入的新测试字符串是:

0________ 1________ 2________ 3________ 4________ 5________ 6________ 7________ 8________ 9________ 10_______ 11_______ 12_______ 13_______ 14_______ 15_______ 16_______ 17_______

它在以下位置切断:

0________ 1________ 2________ 3________ 4________ 5________ 6________ 7________ 8________ 9________ 10_______ 11_______ 12_______ 13_______ 14_______

带有小文本(五行)和

0________ 1________ 2________ 3________ 4________ 5________ 6________ 7________ 8________ 9________ 10_______ 11_______

中等文本(六行)。

进一步编辑:

缩短字符串表明它正在切断最后一两行。可能像Android: Last line of textview cut off。在字符串文件中添加换行符会给我另一行,但不是整个字符串!

【问题讨论】:

  • 您能否添加更多代码部分,例如您的所有 LinearLayout 代码。
  • 请张贴你的问题的截图

标签: android layout textview


【解决方案1】:

尝试为您的文本视图使用以下属性

android:maxLines="10"

android:ellipsize="none"

android:singleLine="false"

【讨论】:

  • 我已经尝试了前两个,但没有尝试过 singleLine(尽管它显示多行的事实有点奇怪)。不过我会试试的!
  • 恐怕一点效果都没有。
  • 尝试在对话框之外测试这个文本视图。编写一个显示此文本视图的简单活动。有没有一样的结果。如果是,在这里发布带有简单活动的整个程序,人们将能够自己测试它。如果不是,则问题与其他问题有关,但至少您会知道调查文本视图没有意义。
  • 万岁!,这至少解决了我的问题:D。显然,android:ellipsize="end" 仅适用于 ICS 或更高版本,并且会弄乱例如GB(我指定了 4 行,它在第 2 行某处切断,这在 ICS 上没有发生)。
  • android:singleLine 现已弃用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多