Encounter a problem is this: When the character TextView displays only one line, narrow height unchanged text size, View of. Why is this so? TextView set for my height wrap_content, why not have the same high degree View of narrow? If I want to shrink it, how to do it?
When TextView is displayed as two lines of text when the problem does not exist. This time the height decrease the text size, View is also reduced.
To confirm this, I deliberately write a Demo in the following:
A string resource:.
AB AB \ nCD
2.main.xml
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: orientation = "vertical">android: id = "@ + id / test"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: background = "# FFFFFF00" />
android: id = "@ + id / btn_changeSize"
android: text = "ChangeSize"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
>
android: id = "@ + id / btn_changeTest"
android: text = "ChangeText"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
>
3.TestActivity.java
public class TestActivity extends Activity {
TextView tvTest;
Button btnChangeSize;
Button btnChangeText;
boolean sizeChanged;
boolean textChanged;
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
tvTest = (TextView) findViewById (R.id.test);
tvTest.setTextSize (30f);
tvTest.setText (R.string.one_line);
btnChangeSize = (Button) findViewById (R.id.btn_changeSize);
btnChangeSize.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
if (sizeChanged) {
sizeChanged = false;
tvTest.setTextSize (30f);
} Else {
sizeChanged = true;
tvTest.setTextSize (18f);
}
}
});
btnChangeText = (Button) findViewById (R.id.btn_changeTest);
btnChangeText.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
if (textChanged) {
textChanged = false;
tvTest.setText (R.string.one_line);
} Else {
textChanged = true;
tvTest.setText (R.string.two_line);
}
}
});
}
} Seeking advice! !
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Not ah, only one line you can also change the Text size Text reduce the height of the outside, fitness has always been a high
Reply:
Under clean look
Reply:
clean under it
Reply:
My version 4.0.3, I heard that this version has this bug. postInvalidate () are not refreshed.
Reply:
I also have the same problem, how to allow view of the highly adaptable height variation the textview? ?
Reply:
Find related topics:
http://stackoverflow.com/questions/9541196/androidtextview-height-doesnt-change-after-shrinking-the-font-size
No comments:
Post a Comment