package cn.juzhong.view.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;
public class CustomTextView extends TextView{
private StaticLayout staticLayout;
private TextPaint tp;
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO Auto-generated method stub
super.onSizeChanged(w, h, oldw, oldh);
initView();
}
private void initView()
{
tp = new TextPaint(Paint.ANTI_ALIAS_FLAG);
tp.setTextSize(getTextSize());
tp.setColor(getCurrentTextColor());
staticLayout = new StaticLayout(getText(), tp, getWidth(), Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
}
@Override
protected void onDraw(Canvas canvas)
{
staticLayout.draw(canvas);
}
}
TextView的重写
最新推荐文章于 2021-10-17 11:43:07 发布