Reputation: 643
I have a project, the problem is the title need 2 line but i want the title just 1 line like this
Am i have to calculate the character ?
Upvotes: 4
Views: 2478
Reputation: 12803
tv.setSingleLine();
tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
Source: How to limit a length of a text in android ListView?
Upvotes: 2
Reputation: 2065
Add these fields to the textview on your xml layout:
android:scrollHorizontally="true"
android:ellipsize="end"
android:maxLines="1"
Upvotes: 2
Reputation: 1223
Method 1: Set singleLine
property to true.
android:maxLines="1"
android:ellipsize="end"
Also, if you want to fit the entire title in one line.
Try setting font size as per screen density:
Create resource folders like:
values-ldpi
values-mdpi
values-hdpi
Create dimensions.xml
file in each folder with appropriate text size:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">15sp</dimen>
</resources>
Set the text in xml or in java file as:
textView.setTextSize(getResources().getDimension(R.dimen.text_size));
Upvotes: -1