Reputation: 1812
I have a TextView with both dimentions WRAP_CONTENT then:
1) I change the text size to 30 for example --> everything goes ok, the width and height of the view are correctly resized
2) then I change the text size to a smaller value (10 for instance) --> FAIL, the width of the view is wrapped to the content, but the height keeps beeing the same as before, not wrapping to the new text height.
It seems when the textView reaches a certain size, it's not able to return to a smaller size.
Note1: If I then force a fixed size trying to restore the wrapped view, it does so, cutting the text, not repositioning it.
Note 2: Tried everything to refresh the view. Setting again the LayoutParams does nothing
The code is simple:
final TextView t = (TextView)findViewById(R.id.text);
t.setText("This is a Test");
t.setBackgroundColor(Color.RED);
Button b0 = (Button)findViewById(R.id.boto0);
b0.setText("Change Size");
b0.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (t.getTextSize()>20){
t.setTextSize(10f);
}else{
t.setTextSize(30f);
}
}
}
Upvotes: 3
Views: 3001
Reputation: 69
Every time you set text do:
setText("I am a Text",TextView.BufferType.SPANNABLE);
See also this question: Android:TextView height doesn't change after shrinking the font size
Upvotes: 2