【发布时间】:2012-03-02 22:22:47
【问题描述】:
当我点击按钮时,字体大小缩小到 12。 但是,结果是:
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 的高度,使其只包裹实际字体?
【问题讨论】:
-
我刚刚测试了您的代码,它可以正常工作。你用的是哪个版本的安卓?
-
我在 Android 3.2 & 4.0 上测试过
-
这些解决方案都不适用于任何版本的 Android。 T__________T