zoukankan      html  css  js  c++  java
  • 自定义控件TextView

    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);
        }
        
  • 相关阅读:
    multi-task learning
    代码杂谈-python函数
    代码杂谈-or符号
    安装maven
    zsh
    mint linux的几个问题
    [软件] Omnigraffle
    无梯度优化算法
    根据pdf文件获取标题等信息
    计算广告-GD广告
  • 原文地址:https://www.cnblogs.com/androidxufeng/p/3654911.html
Copyright © 2011-2022 走看看