安卓:TextView的高度缩小字体大小后,不会改变 [英] Android:TextView height doesn't change after shrinking the font size

查看:577
本文介绍了安卓: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的:

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+

<一个href="http://$c$c.google.com/p/android/issues/detail?id=17343&can=1&q=textview%20setTextSize%20height&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars">Issue 17343

<一个href="http://$c$c.google.com/p/android/issues/detail?id=22493&can=1&q=textview%20setTextSize%20height&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars">Issue 22493

可能的解决方法是:

text.setText(text+"\n");

final String DOUBLE_BYTE_SPACE = "\u3000";
text.setText(text + DOUBLE_BYTE_SPACE);

这篇关于安卓:TextView的高度缩小字体大小后,不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆