隐藏键盘后防止ImageView重绘状态

时间:2013-12-16 07:57:20

标签: android android-imageview

首先,我有这样的观点:

enter image description here

当用户在edittext中按某些文本时,我尝试使用特定坐标在ImageView中绘制一些矩形。问题是当软键盘被隐藏时,Imageview的所有绘制状态显示错误的坐标,看起来像使图像视图无效。我想知道有没有办法阻止这一点。 这是我的Custom Drawable Imageview:

public class DrawableImageView extends ImageView {
private Paint ptBlur;
private List<Rect> rects;
private int originWidth;
private int originHeight;

public DrawableImageView(Context context) {
    super(context);
    initPaint();
}

public DrawableImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initPaint();
}

public DrawableImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initPaint();
}

public void setRects(List<Rect> rects, int originWidth, int originHeight) {
    this.originHeight = originHeight;
    this.originWidth = originWidth;
    this.rects = rects;
    invalidate();
}

private void initPaint() {
    ptBlur = new Paint();
    ptBlur.setColor(Color.YELLOW);
    ptBlur.setStyle(Paint.Style.STROKE);
    ptBlur.setStrokeWidth(5);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (rects != null) {
        int width = getWidth();
        int height = getHeight();
        for (Rect rect : rects) {
            rect.bottom = Math.round(height * rect.bottom / originHeight);
            rect.left = Math.round(width * rect.left / originWidth);
            rect.right = Math.round(width * rect.right / originWidth);
            rect.top = Math.round(height * rect.top / originHeight);
            canvas.drawRect(rect, ptBlur);
        }
    }
}
}

EditText的OnEditorActionListener

  // get the rectangles and draw 
  List<Rect> rects = DataUtil.getHighlightRectList(searchText);
  drawableImageView.setRects(rects, pageWidth, pageHeight);

0 个答案:

没有答案