当我按一下按钮,字体大小缩小到12 然而,结果是:安卓:TextView的高度不缩小字体大小后更改
的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);
}
});
}
}
如何至尊nk textView的高度,以便它只包裹实际的字体?
我只是测试你的代码和它的作品,因为它应该。你使用的是哪个版本的Android? – caiocpricci2 2012-03-03 07:16:00
我在Android 3.2&4.0上进行了测试 – jclova 2012-03-05 15:45:18
这些解决方案都不适用于任何Android版本。 T__________T – Magicode 2014-07-08 22:08:04