當我按一下按鈕,字體大小縮小到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