0

I have problem in resizing the text view .

I have a Layout like this with below components

ImageView| TextView | ImageView

placed in relativelayout(horizontal) and each one width is wrap content and height is fill parent.

PROBLEM

I have a text like this "My name","My name is xyzmnop" now, i have fixed the TextView size to 15sp, so what is happening is in larger devices since Textviews width increases the text "My name is xyzmnop" will fit but in smaller devices since the width is small it will spill out to second line. But i want it to be in same line, as I have the flexibility to decrease the size of the text if the text is lengthy.

please help me with this problem.

i have seen this

EDIT:

I have also added setSingleLine = "true"; in my xml

Community
  • 1
  • 1
Goofy
  • 6,098
  • 17
  • 90
  • 156
  • What is your actual question? As the answers below seem to answer the question you posted... (but are not the answer you seem to desire) – Veger Jan 02 '13 at 11:05

3 Answers3

1

Say, tv is your TextView.

Just call tv.setMaxLines(1);

Charlie-Blake
  • 10,832
  • 13
  • 55
  • 90
  • no thats not the point i want the textview to be in single line and i have added that in xml, problem is with the test size – Goofy Jan 02 '13 at 10:48
  • 2
    Downvoting won't get you an answer sooner. Anyway, you're clearly asking how to make a TextView text show in just one line, and that's what we provided. Maybe you wanted other thing, if you want the answers, learn to make the questions. – Charlie-Blake Jan 02 '13 at 10:52
  • Also, maybe you will want to check this out: http://stackoverflow.com/questions/3630086/how-to-get-string-width-on-android – Charlie-Blake Jan 02 '13 at 10:55
0

TextView has the setMaxLines (int maxlines) method:

Makes the TextView at most this many lines tall. Setting this value overrides any other (maximum) height setting.

I suppose this might help you if you set the maximum number of lines to 1.

Note: there is also the android:maxlines attribute if you need to set it in your XML layout.

Veger
  • 37,240
  • 11
  • 105
  • 116
-1

i have solved it using ViewTreeObserver.

Goofy
  • 6,098
  • 17
  • 90
  • 156