4

enter image description here

I have a project, the problem is the title need 2 line but i want the title just 1 line like this

enter image description here

Am i have to calculate the character ?

Josh Parinussa
  • 633
  • 2
  • 11
  • 28

3 Answers3

2
  tv.setSingleLine();
  tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);

Source: How to limit a length of a text in android ListView?

Community
  • 1
  • 1
John Joe
  • 12,412
  • 16
  • 70
  • 135
2

Add these fields to the textview on your xml layout:

android:scrollHorizontally="true"
android:ellipsize="end" 
android:maxLines="1"
HaroldSer
  • 2,025
  • 2
  • 12
  • 23
-1

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));
Suhayl SH
  • 1,213
  • 1
  • 11
  • 16