public class CustomAuthView extends android.support.v7.widget.AppCompatTextView { private StaticLayout myStaticLayout; private TextPaint tp; public CustomAuthView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); initView(); } //StaticLayout 百度查看该api的参数 private void initView() { tp = new TextPaint(Paint.ANTI_ALIAS_FLAG); tp.setTextSize(getTextSize()); tp.setColor(getCurrentTextColor()); myStaticLayout = new StaticLayout(getText(), tp, getWidth(), Layout.Alignment.ALIGN_CENTER, 1.0f, Util.dip2px(getContext(),5), false); } @Override protected void onDraw(Canvas canvas) { myStaticLayout.draw(canvas); } }
自定义view,自动切换到下一行时居中显示
最新推荐文章于 2021-06-29 19:42:04 发布