Android中的多行TextView? [英] Multiline TextView in Android?

查看:49
本文介绍了Android中的多行TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 xml

<TableRow>
    <TextView android:id="@+id/address1"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:gravity="left"
        android:maxLines="4" 
        android:singleLine="false"              
        android:text="Johar Mor, Gulistan-e-Johar, Karachi" >
    </TextView> 
</TableRow>

它不适用于 multiline,我正在使用 TableLayout...

It is not working for multiline, and I am using TableLayout...

那么我在这里做错了什么?

so what is mistake I am doing here?

推荐答案

如果你放入TextView的文字很短,它不会自动展开为四行.如果您希望 TextViewalways 有四行而不管其中文本的长度,请设置 android:lines 属性:

If the text you're putting in the TextView is short, it will not automatically expand to four lines. If you want the TextView to always have four lines regardless of the length of the text in it, set the android:lines attribute:

<TextView
    android:id="@+id/address1"
    android:gravity="left"
    android:layout_height="fill_parent"
    android:layout_width="wrap_content"
    android:maxLines="4"
    android:lines="4"
    android:text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."></TextView>

你可以用 TableRow 做到这一点,见下面的代码

You can do this with TableRow, see below code

<TableRow >
        <TextView
            android:id="@+id/tv_description_heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="8dp"
            android:text="@string/rating_review"
            android:textColor="@color/black"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/tv_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:maxLines="4"`enter code here`
            android:padding="8dp"
            android:text="The food test was very good."
            android:textColor="@color/black"
            android:textColorHint="@color/hint_text_color" />
    </TableRow>

这篇关于Android中的多行TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆