1

I am making an app that has two EditText views, txtOne which is used for input, and txtTwo which is used for output. txtOne is editable, and txtTwo is not.

I am looking for a simple way to scale the font size of the text in these two views so that it always fits within the view without wrapping to a new line.

I have found a few implementations of this using custom views extending TextView, but they aren't fit for an EditText view, or use android.graphics.Paint, which is not what I am looking for.

Is there any way to check to see when text in an EditText view is wrapping? If so, then it would be easy enough to do something like:

if(txtOne.isWrappingText()) {
    txtOne.setTextSize(txtOne.getTextSize() - 2);
}

Does anyone know of any way to detect this or an alternative solution?

WilHall
  • 9,994
  • 5
  • 28
  • 52

1 Answers1

3

I deleted my post

Basically the suggested code contained a TextWatcher for the EditText, this helped to answer the question. But the code itself was just wrong (I tested it meanwhile).

I suggest to read this question and answers because they adress the very same issue...

Community
  • 1
  • 1
Knickedi
  • 8,572
  • 2
  • 40
  • 45
  • +1 for TextWatcher -- I forgot that you can use the beforeTextChanged event in a TExtWatcher, where you can't when making a custom EditText view. This specific example, however, just makes the font size very-very small from the start. I feel like something in my code is causing the text changed event to fire multiple times, but that's another issue in my case: I do a lot of subtle changes to the text content, so that's bound to happen. Still looking for different solutions – WilHall Sep 25 '11 at 01:17
  • 1
    I'm so dump ;-) I think you ment [this post](http://stackoverflow.com/questions/2617266/how-to-adjust-text-font-size-to-fit-textview/3378422#3378422) in your question. My idea matches that one exactly (even the improvement by a binary search ;-), but he has provided a complete implementation. Have you tried to use that and simply extend an `EditText` instead of a `TextView` (since `EditText` extends `TextView` anyways). – Knickedi Sep 25 '11 at 03:07
  • I found that post a little earlier, and I was looking at it. I think I've found a solution for my very specific case (nothing general i could share). I have a lot of handlers set up already, and so I basically did some calculations in those to adjust the font size. – WilHall Sep 25 '11 at 04:22