-1

I have a Text view that has a max width of (200 dp). And I have a string that varies in length.

Example

Lets say that the string is this:

   String example= "this is a test string";

question:

I want to know if is it possible to check if the length of the string is equal to the text view's maximum width?

Thank you.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0

Replace this:

textPaint.getTextBounds(text, 0, text.length(), bounds); 

With this:

textPaint.getTextBounds(text, 0, example.length(), bounds); 

That information is from this answer that may probably help you.

Abhishek Jain
  • 3,562
  • 2
  • 26
  • 44
0

Add android:singleLine="true" in your text view to solve your problem.

<TextView
        android:text="this is a test stringthis is a test string
        this is a test stringthis is a test string"
        android:singleLine="true"
        android:background="@color/colorAccent"
        android:layout_width="200dp"
        android:layout_height="wrap_content" />
Kaushal Gosaliya
  • 421
  • 7
  • 16