TextView 换行(多行)问题

TextView new line (in multiline) issues

目前我正在为多行文本视图获取此结果 -

maxLines = 2

如果文本是 -

Hello hfhfhfhfhfhfhhfhfhfhfhfhhfhfhf

那么输出是:

但我需要这样的:

请帮我得到这个结果:)

XML 是

<TextView
            android:id="@+id/user_name"
            style="@style/default_text_font_face"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:scrollHorizontally="true"
            android:maxLines="2"
            android:text="Hello hffffffhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhhfhfhhfhfhfhfhhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhf"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" />

你有以下用途属性..

android:maxWidth="size"

size 替换为您喜欢的尺寸。例如,100dip.

更新日期:

xml 文件

<TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:maxLines="2"
        android:maxWidth="50dip"
        android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="15dp" />

输出:

更新 2 :

使用 match_parent.

<TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:maxLines="2"
            android:maxWidth="50dip"
            android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="15dp" />

输出:

使用

 android:layout_width="match_parent"

给你的TextView

EDIT1

试试下面的方法

<TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#535353"
    android:textColor="#ffffff"
    android:maxLines="2"
    android:text="Best Effffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffff"
    android:textSize="20dp"/>

</LinearLayout>

Output

希望对您有所帮助