【发布时间】:2015-07-04 21:07:49
【问题描述】:
我想了解字体大小,尤其是与 Android 的密度无关像素有关的信息。 10 号字体与 11 号字体有什么不同?
我问这个问题是因为我有一个问题,如下所述。
我在我的 Android 应用程序中定义了这个自定义 TextView 以支持我的语言和英语。 TextView 会根据应用程序的语言设置更改字体。
public class MyanmarTextView extends TextView {
public MyanmarTextView(Context context) {
super(context);
String fontName = "fonts/OpenSans.ttf";
String language = context
.getSharedPreferences("org.bitbucket.infovillafoundation.denko", Context.MODE_PRIVATE)
.getString("org.bitbucket.infovillafoundation.denko.language", "en");
if (language.equals("my"))
fontName = "fonts/WINNWAB.ttf";
Typeface face = Typeface.createFromAsset(context.getAssets(), fontName);
this.setTypeface(face);
}
public MyanmarTextView(Context context, AttributeSet attrs) {
super(context, attrs);
String fontName = "fonts/OpenSans.ttf";
String language = context
.getSharedPreferences("org.bitbucket.infovillafoundation.denko", Context.MODE_PRIVATE)
.getString("org.bitbucket.infovillafoundation.denko.language", "en");
if (language.equals("my"))
fontName = "fonts/WINNWAB.ttf";
Typeface face = Typeface.createFromAsset(context.getAssets(), fontName);
this.setTypeface(face);
}
public MyanmarTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
String fontName = "fonts/OpenSans.ttf";
String language = context
.getSharedPreferences("org.bitbucket.infovillafoundation.denko", Context.MODE_PRIVATE)
.getString("org.bitbucket.infovillafoundation.denko.language", "en");
if (language.equals("my"))
fontName = "fonts/WINNWAB.ttf";
Typeface face = Typeface.createFromAsset(context.getAssets(), fontName);
this.setTypeface(face);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
问题是本地语言的字体大小需要大于英文的字体大小。例如,要创建将英文文本设置为字体大小 10 的外观,本地语言文本的字体大小应为 13。如果我希望字体大小由TextView 自动设置,是否添加给定字体大小的常数值还是将其乘以常数?还是完全不同?
【问题讨论】: