安卓:TextView的高度缩小字体大小后,不会改变字体大小、高度、TextView

2023-09-12 22:39:29 作者:跟我不会错;

当我按一下按钮,字体大小缩小到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+

Issue 17343

Issue 22493

可能的解决方法是:

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

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