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