Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to influence linebreak in Android Textview

I have an Appwidget displaying days until an event like:

eventname (-231 days)

If possible I want to display this String in one line. If the eventname is too long I want to display the full term in braces into a new line. So that it is like:

longeventname
(-231 days)

instead of:

longeventname (-231
days)

(or anything similar)

Is there a way to archive this? Can I make (-231 days) "atomic"?

string.getLength won't work since the size of the widget will vary by device.

like image 828
Tobias Avatar asked Nov 20 '11 17:11

Tobias


People also ask

How to add line break in text view?

Add Line Breaks to a TextView Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.

How to break line in xml Android?

Add \t for tab and \n for new line.

How to add new line in Android studio?

for the new line in TextView just add \n in middle of your text it works..

How do you put line through text on Android?

If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.


1 Answers

You could use a non-breaking space between the number and "days".

That's   for a string in XML, or \u00A0 for a string in Java code.

like image 135
Martin Stone Avatar answered Oct 15 '22 00:10

Martin Stone