【发布时间】:2015-05-26 16:23:52
【问题描述】:
我尝试将文本视图添加到位置 0,0 的相对布局!
使用以下代码:
TextView text = new TextView(getActivity());
text.setTextColor(Color.RED);
text.setIncludeFontPadding(false);
text.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, 32 * getResources().getDisplayMetrics().density);
text.setText("TEST TEXT");
text.setSingleLine(false);
text.setX(0);
text.setY(0);
text.setTypeface(fct.getFont().getTypeFace(getActivity())); container.addView(text);
容器是这里定义的相对布局:
<RelativeLayout
android:id="@+frontcard/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
我在 textview 中使用自定义字体...
问题是文本视图显示不正确。 顶部有一个填充...左侧设置正确。
输出图像:
如果我把它画在画布上,一切正常,如下图所示:
文本视图中的自定义字体有问题吗?
有人有什么想法吗?
【问题讨论】:
-
我不确定,但 TextView 在顶部和底部有自然边距,试试 text.setGravity(Gravity.TOP);
-
好主意...不幸的是它不起作用:/我猜自定义字体的填充有些问题