首页 > 其他 > 详细

自定义控件TextView

时间:2014-04-09 23:31:16      阅读:522      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

bubuko.com,布布扣
public class defineTextView extends TextView {
    
    Context context;
public defineTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
        this.context=context;
    }
    public defineTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        this.context=context;
    }
    public defineTextView(Context context) {
        super(context);    
        this.context=context;
    }
    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
            Drawable[] drawable=getCompoundDrawables();
            int drawablewidth=drawable[0].getIntrinsicWidth();
            float textwidth=getPaint().measureText(getText().toString());
            int drawablepadding=getCompoundDrawablePadding();
            int bodywidth=(int) (drawablepadding+textwidth+drawablewidth);
            canvas.translate((getWidth()-bodywidth)/2, 0);
            canvas.drawLine(0, getHeight(), getWidth(), getHeight(), getPaint());
        super.onDraw(canvas);
    }
    @Override
    public void setTextSize(float size) {
        
        super.setTextSize(size);
    }
    
bubuko.com,布布扣

 

自定义控件TextView,布布扣,bubuko.com

自定义控件TextView

原文:http://www.cnblogs.com/androidxufeng/p/3654911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!