Reputation: 6188
I would like to know about font sizes especially in relation to Android's density independent pixel. In what ways a font size of 10 is different from a font size of 11?
I am asking this question because I have a problem which is described below.
I have defined this custom TextView
in my Android app to support my language as well as English. The TextView
changes fonts depending on language settings of the app.
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);
}
}
The problem is that the font size of the local language needs to be larger than the font size of English. For example to create that look and feel that one gets with an English text set at font size 10, the font size of the local language text should be 13. If I want the font size to automatically set by TextView
, do I add a constant value to the given font size or do I multiply it by a constant? Or is it something different altogether?
Upvotes: 0
Views: 83
Reputation: 25194
I assume it depends on your custom font WINWAB.ttf
, which might be smaller than OpenSans.ttf
. It actually has nothing to do with android sizes, for which 10sp
is different from 11sp
just for the latter being bigger.
I would suggest testing sizes and trying to find some relation among the OpenSans.ttf
and the WINWAB.ttf
rendered sizes. Adding +3
might be worth considering, and you are lucky enough to already have a custom view, so it is easy to implement.
Upvotes: 1
Reputation: 2486
I don't know if I got you right but try this ->
this.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
or any thing you want instead of 14
Upvotes: 0