zoukankan      html  css  js  c++  java
  • 字体描边 终极版

    package com.joyodream.common.view;
    
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Paint.Style;
    import android.text.TextPaint;
    import android.util.AttributeSet;
    import android.view.ViewGroup;
    import android.widget.TextView;
    
    /**
     * 
     * 描边,默认是灰色描边
     * 
     * @author lipeilong
     *
     */
    public class JDStrokeTextView extends TextView {
         
        private TextView borderText = null;
        private final int STROKE_WIDTH        = 6;  // 线宽度
     
        public JDStrokeTextView(Context context) {
            super(context);
            borderText = new TextView(context);
            init();
        }
     
        public JDStrokeTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            borderText = new TextView(context,attrs);
            init();
        }
     
        public JDStrokeTextView(Context context, AttributeSet attrs,
                int defStyle) {
            super(context, attrs, defStyle);
            borderText = new TextView(context,attrs,defStyle);
            init();
        }
     
        public void init(){
            TextPaint tp1 = borderText.getPaint(); 
            tp1.setStrokeWidth(STROKE_WIDTH);                                  
            tp1.setStyle(Style.STROKE);                             
            borderText.setTextColor(0xff333333);  
            borderText.setGravity(getGravity());
        }
     
        @Override
        public void setLayoutParams (ViewGroup.LayoutParams params){
            super.setLayoutParams(params);
            borderText.setLayoutParams(params);
        }
     
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            CharSequence tt = borderText.getText();        
            if(tt== null || !tt.equals(this.getText())){
                borderText.setText(getText());
                this.postInvalidate();
            }
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            borderText.measure(widthMeasureSpec, heightMeasureSpec);
        }
     
        protected void onLayout (boolean changed, int left, int top, int right, int bottom){
            super.onLayout(changed, left, top, right+STROKE_WIDTH, bottom);
            borderText.layout(left, top, right+STROKE_WIDTH, bottom);// 总要,否则会截断部分文字
        }
     
        @Override
        protected void onDraw(Canvas canvas) {
            borderText.draw(canvas);
            super.onDraw(canvas);
        }
     
    }

    网上找的几种解决方案中,这个是最靠谱的了。使用系统自带的阴影也是可以实现部分效果,看情况选择使用
  • 相关阅读:
    通达OA 新旧两种数据库连接方式
    c++ 如何获取系统时间
    性能测试开源小工具——http_load介绍
    http_load安装与测试参数分析
    不错的C++框架: Thrift(2)-传输和网络相关
    管理处理器的亲和性(affinity)
    300元内,此耳机是首选。不亏千人好评,对的起你的耳朵。
    [品质生活] 舒适 Schick HYDRO 5剃须刀
    巴氏刷牙法_百度百科
    Amazon.com : The Odyssey of the Manual Toothbrusher
  • 原文地址:https://www.cnblogs.com/lipeil/p/5029290.html
Copyright © 2011-2022 走看看