我正在创建具有自定义背景的自定义EditText
。但它的工作原理错误。我在视图的底部创建了一条线。这条线是动画的。它运作良好。但是,如果我开始输入文字,那么就行了。
我的自定义视图:
public class DrawView extends EditText {
private Paint paint;
private Paint paintBefor;
private float value;
public DrawView(Context context) {
super(context);
init();
}
private void init() {
paint = new Paint();
paintBefor = new Paint();
value = 0.0f;
paint.setColor(Color.WHITE);
paintBefor.setColor(Color.RED);
paint.setStrokeWidth(10);
paintBefor.setStrokeWidth(10);
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawARGB(20, 102, 204, 255);
int halfWidth = getWidth() / 2;
canvas.drawLine(0,getHeight(),getWidth(),getHeight(), paintBefor);
canvas.drawLine(halfWidth,getHeight(), halfWidth + value * halfWidth,getHeight(), paint);
canvas.drawLine((1.0f - value) * halfWidth, getHeight(), halfWidth, getHeight(), paint);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
public void startSkipAnimation() {
ValueAnimator.AnimatorUpdateListener animatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
setProgress((Float) valueAnimator.getAnimatedValue());
}
};
ValueAnimator progressAnimator = ValueAnimator.ofFloat(0.0f,1.0f);
progressAnimator.addUpdateListener(animatorUpdateListener);
progressAnimator.setInterpolator(new DecelerateInterpolator());
progressAnimator.setDuration(1500);
progressAnimator.start();
}
private void setProgress(float value){
this.value = value;
invalidate();
}
}
它看起来像这样: http://markevans.github.io/dragonfly/rails/
我想在输入文字时显示背景线。