Android Textview缩进之悬挂缩进

    

很多地方都需要用到类似这样的悬挂缩进,排版看起来比较整齐。代码实现起来也很简单,几行就搞定了。

String str = "1. Because of the protocol implementation on Philips Hue lights, it is not possible to remotely factory reset the lights. Instead a separate Philips Dimmer Switch is required to proceed. \n2. With the Philips Dimmer Switch in hand, bring it within 4 inches / 10 cm of the bulb or lamp you wish to factory reset, then press and hold the I and 0 buttons simultaneously. \n3. Continue holding for 10 seconds until the green LED illuminates on the dimmer switch, the bulb will flash just before receiving the green LED. The bulb is now reset and can be re-included.";

Paint tvPaint = tvAuto.getPaint();
float rawIndentWidth = tvPaint.measureText("1. ");
SpannableString spannableString = new SpannableString(str);
LeadingMarginSpan.Standard what = new LeadingMarginSpan.Standard(0, (int) rawIndentWidth);
spannableString.setSpan(what, 0, spannableString.length(), SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
tvAuto.setText(spannableString);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值