如何降低TextView的文本大小的Android 4.0? [英] How to decrease TextView text size in Android 4.0?
问题描述
(编辑:固定的问题,请参见下面的答案)
( problem fixed. See answer below)
我坚持这个问题,它阻止释放所以每一个帮助将大大AP preciated。
I am stuck with this issue and it blocks a release so every help will be greatly appreciated.
下面是一个演示问题一个简单的程序。我用最新的SDK(R19)建造它。它运作良好的姜饼但未能上ICS。当文本大小增加(10 - > 30 - > 50)的文本字段高度增长预期,但是当文本大小减少(50 - > 10),则文本字段有充分的高度,如果文本大小50。
Below is a trivial program that demonstrates the issue. I built it with the latest SDK (R19). It works well on gingerbread but fails on ICS. When the text size is increased (10 -> 30 -> 50) the text field height grows as expected but when the text size is reduced (50 -> 10), the text field has the full height, as if the text size is 50.
任何人都可以复制吗?一个解决办法的任何建议,以减少文字大小正常工作?
Anybody can reproduce it? Any suggestion for a workaround to make reduction in text size working properly?
主要活动:
包test.resize;
Main activity: package test.resize;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class ResizeTestActivity extends Activity {
private int mNextTextSize = 10;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textView = (TextView) findViewById(R.id.text0);
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Cycle to next text size in {10, 30, 50}
textView.setText("Text Size " + mNextTextSize);
textView.append("\uFEFF"); // <--- THE FIX (see answer below)
textView.setTextSize(mNextTextSize);
// textView.requestLayout(); // does not help
// textView.invalidate(); // does not help
mNextTextSize = (mNextTextSize >= 50) ? 10 : (mNextTextSize + 20);
}
});
}
}
主要布局:
<?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="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click To Cycle Text Size" />
<TextView android:id="@+id/text0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dip"
android:background="#ffffff00"
android:text=""/>
</LinearLayout>
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.resize"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ResizeTestActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
推荐答案
回答我的问题。 Apparantly这是报告的bug。
Answering my own question. Apparantly this is a reported bug.
HTTP://$c$c.google。 COM / p /安卓/问题/细节?ID = 22493
添加
tv.append("\uFEFF"); // zero width space
后设置TextView的文本解决了这个问题。
after setting the TextView text solves the problem.
注:如果您使用自定义的字体,请确保它包含\\ uFEFF字符。如果没有,你也可能有一行省略号问题。
Note: if you are using custom font, make sure it contains the \uFEFF character. If not, you may also have problems with single line ellipsis.
这篇关于如何降低TextView的文本大小的Android 4.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!