机器人,如何绘制的EditText虚线 [英] android, how to draw dotted line in edittext

查看:538
本文介绍了机器人,如何绘制的EditText虚线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我refered此链接:我如何做一个点/虚线的Andr​​oid?和使用 DashPathEffect 。但是,这并不为我工作?为什么?我的code:

 公共类NoteEditText扩展的EditText {
    私人油漆mPaint;

    公共NoteEditText(上下文的背景下){
        超(上下文);
    }

    公共NoteEditText(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
        mPaint =新的油漆();
        mPaint.setStrokeWidth(1);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.DKGRAY);
        PathEffect效果​​=新DashPathEffect(新浮法[] {5,5,5,5},1);
        mPaint.setPathEffect(效果);
    }

    @覆盖
    公共无效的OnDraw(帆布油画){
        super.onDraw(画布);

        INT高= this.getHeight();
        INT lineHeight是= this.getLineHeight();
        INT LINENUM =身高/ lineHeight是;
        L.l(行数:+ LINENUM);
        的for(int i = 0; I< LINENUM;我++){
            INT Y =第(i + 1)* lineHeight是;
            canvas.drawLine(0,Y,this.getWidth() -  1,Y,mPaint);
        }
    }
}
 

解决方案

该方法setPathEffect不受硬件加速的支持。默认情况下它是打开的(我认为,由于Android 4.0)

http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported

您可以关闭硬件加速在构造函数中具有以下code片断:

  

setLayerType(View.LAYER_TYPE_SOFTWARE,NULL);

I refered to this link: How do I make a dotted/dashed line in Android?, and used DashPathEffect. But this does not work for me? why? my code:

public class NoteEditText extends EditText {
    private Paint mPaint;

    public NoteEditText(Context context) {
        super(context);
    }

    public NoteEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setStrokeWidth(1);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.DKGRAY);
        PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);  
        mPaint.setPathEffect(effects);
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int height = this.getHeight();
        int lineHeight = this.getLineHeight();
        int lineNum = height / lineHeight;
        L.l("line count: " + lineNum);
        for (int i = 0; i < lineNum; i++) {
            int y = (i + 1) * lineHeight;
            canvas.drawLine(0, y, this.getWidth() - 1, y, mPaint);
        }
    }
}

解决方案

The method setPathEffect is not supported by hardware acceleration. By default it is turned on (I think since Android 4.0)

http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported

You can turn off hardware acceleration inside the constructor with following code snippet:

setLayerType(View.LAYER_TYPE_SOFTWARE, null);

这篇关于机器人,如何绘制的EditText虚线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆