Android文字头部被切掉,Android textview文本在自定义字体的两侧被切断

本文讨论了在Android中遇到的问题,即使用自定义字体时,TextView的文字头部(如“j”和“f”)被切掉。尝试设置填充或边距无效。解决方案是创建一个自定义TextView并覆盖onDraw方法来避免文字被截断。
摘要由CSDN通过智能技术生成

这是在预览和设备上发生的事情:

7ffb28c778bf0e9cf2c7769e526b8fb2.png

TextView没什么特别的,只是加载自定义字体:

public class TestTextView extends AppCompatTextView {

public TestTextView(Context context) {

super(context);

init(context);

}

public TestTextView(Context context, AttributeSet attrs) {

super(context, attrs);

init(context);

}

public TestTextView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

init(context);

}

void init(Context context) {

Typeface t = Typeface.createFromAsset(context.getAssets(), "fonts/daisy.ttf");

setTypeface(t);

}

}

布局也很基础,但以防万一:

xmln

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值