Android:缩小字体大小后TextView高度不会改变 [英] Android:TextView height doesn't change after shrinking the font size
本文介绍了Android:缩小字体大小后TextView高度不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击按钮时,字体大小缩小到 12.但是,结果是:
When I click on the button, the font size shrinks to 12. However, the result is :
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:background="#80ff0000"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
java:
public class FontSizeTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView text = (TextView) findViewById(R.id.test);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text.setTextSize(12);
}
});
}
}
如何缩小 textView 的高度,使其只包裹实际字体?
How do I shrink the height of the textView so that it only wraps the actual font?
推荐答案
终于找到原因/解决方案了!!!
Finally, I found the reason/solution!!!
这是 Android 3.1+ 的已知错误
This is a known bug for Android 3.1+
可能的解决方法是:
text.setText(text+"
");
或
final String DOUBLE_BYTE_SPACE = "u3000";
text.setText(text + DOUBLE_BYTE_SPACE);
这篇关于Android:缩小字体大小后TextView高度不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文