Reputation: 2727
currently I am getting this result for a multiLine text view -
maxLines = 2
If text is -
Hello hfhfhfhfhfhfhhfhfhfhfhfhhfhfhf
Then output is :
But I need it like this :
Please help me to get this result :)
XML is
<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" />
Upvotes: 0
Views: 670
Reputation: 4335
Use
android:layout_width="match_parent"
to your TextView
EDIT1
Try the following way
<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
I hope this may helps you
Upvotes: 1
Reputation: 20910
you have use below property..
android:maxWidth="size"
Replace the size
with the size you prefer. For example, 100dip
.
UpDate :
xml file
<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" />
Output :
UpDate 2 :
using 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" />
output :
Upvotes: 0