[英]Textview alignment issue when changing font/text size
I have looked through quite a few answers and questions here on stackoverflow but have not found anything really helpful regarding my problem. 我在stackoverflow上看了很多答案和问题,但没有找到任何关于我的问题真正有用的东西。
I have two textviews of equal size and equal properties right next to each other, the xml layout is this (only textsize differ) 我有两个相同大小和相同属性的文本视图彼此相邻,xml布局是这样的(只有文本大小不同)
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/data_content_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".50"
android:gravity="bottom|center"
android:text="201.5"
android:textSize="50sp"
android:textStyle="bold"
android:singleLine="true"
android:ems="62" />
<TextView
android:id="@+id/data_content_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.50"
android:ems="62"
android:gravity="center|bottom"
android:singleLine="true"
android:text="201.5"
android:textSize="20sp"
android:textStyle="bold" />
and the code is this 而代码就是这个
package com.example.fonttest; package com.example.fonttest; import android.os.Bundle;
import android.os.Bundle; import android.app.Activity;
import android.app.Activity; import android.graphics.Typeface;
import android.graphics.Typeface; import android.view.Menu;
import android.view.Menu; import android.widget.LinearLayout;
import android.widget.LinearLayout; import android.widget.TextView;
import android.widget.TextView;
public class MainActivity extends Activity { 公共类MainActivity扩展Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textViewLeft = (TextView) findViewById(R.id.data_content_left);
TextView textViewRight = (TextView) findViewById(R.id.data_content_right);
Typeface myTypeface = Typeface.createFromAsset(this.getAssets(), "fonts/wwDigital.ttf");
textViewLeft.setTypeface(myTypeface, Typeface.NORMAL);
textViewRight.setTypeface(myTypeface, Typeface.NORMAL);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
} }
Why is the height of the 'white space' below the numbers changing with text/font size? 为什么数字下方的“空白区域”的高度随文本/字体大小而变化? (se image below)
(见下图)
How can I determine if the problem has something to do with the font or with the textview? 如何确定问题是否与字体或textview有关?
I'm using this font: [ http://www.dafont.com/ww-digital.font][3] 我正在使用这种字体:[ http://www.dafont.com/ww-digital.font] [3 ]
对文本视图使用相同的字体即ttf ,并在Textview中使用android:ems来定义它的最大值和最小值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.