2

ここから取得したライブラリであるアプリケーションに拡大鏡ビューを使用しています:

https://github.com/nomanr/android-image-magnifier

このクラスを変更して FrameLayout (以前は ImageView でした) を拡張し、FrameLayout で動作するようにしました。

ペイントされたキャンバス ビューが、そのカスタム ビューに追加されたすべてのビューの後ろに留まることを除いて、うまく機能しています。

それらの追加されたビューの前にそのキャンバスを表示する方法は?

私が使用しているカスタムビュークラス:

public class ImageMagnifier extends FrameLayout {

private PointF zoomPos;
private boolean zooming = false;
private Matrix matrix;
private Paint paint;
private Bitmap bitmap;
private BitmapShader shader;
private int sizeOfMagnifier = 300;
int cheight, cwidth;

Context con;
C c = C.getInstance();
public ImageMagnifier(Context context) {
    super(context);
    init();
    con=context;
}

public ImageMagnifier(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
    con=context;
}

public ImageMagnifier(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    con=context;
}

private void init() {
    zoomPos = new PointF(0, 0);
    matrix = new Matrix();
    paint = new Paint();

    cwidth = c.Width * 109 / 1280;
    cheight = cwidth * 134 / 109;
}

public void otherTouch(int x, int y) {
    if (x > c.getwidth1(28) && x < c.getwidth1(921) && y > c.getheight1(135) && y < c.getheight1(560)) {
        zoomPos.x = x - 10;
        zoomPos.y = y - 75;
        zooming = true;
        this.invalidate();

    } else {
        RemoveMagnifire();
    }
}

public void RemoveMagnifire() {
    zooming = false;
    this.invalidate();
}

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

    if (!zooming) {
        buildDrawingCache();
    } else {

        bitmap = getDrawingCache();
        shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,Shader.TileMode.CLAMP);        
        paint.setShader(shader);
        matrix.reset();
        matrix.postScale(2f, 2f, zoomPos.x-10, zoomPos.y+60);

        paint.getShader().setLocalMatrix(matrix);

        int width = c.Width;
        int height = c.Height;

        float leftX = zoomPos.x - ((width * 100) / 1280);
        float topY = zoomPos.y - ((height * 250) / 720);
        float rightX = zoomPos.x +  ((width * 100) / 1280);
        float bottomY = zoomPos.y - ((height * 100) / 720);

        canvas.drawRect(leftX , topY, rightX, bottomY, paint);


    }
}

}
4

1 に答える 1

2

Aはメソッド内でViewGroup子を描画します。その後、拡大鏡の描画を移動する必要があります。ViewdispatchDraw()

修正は簡単です。の通話後のすべてを のsuper通話のonDraw()後に移動superしますdispatchDraw()

...

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // Removed
}

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (!zooming) {
        buildDrawingCache();
    }
    else {
        bitmap = getDrawingCache();
        shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        paint.setShader(shader);
        matrix.reset();
        matrix.postScale(2f, 2f, zoomPos.x - 10, zoomPos.y + 60);

        paint.getShader().setLocalMatrix(matrix);

        int width = c.Width;
        int height = c.Height;

        float leftX = zoomPos.x - ((width * 100) / 1280);
        float topY = zoomPos.y - ((height * 250) / 720);
        float rightX = zoomPos.x +  ((width * 100) / 1280);
        float bottomY = zoomPos.y - ((height * 100) / 720);

        canvas.drawRect(leftX , topY, rightX, bottomY, paint);
    }
}

...

onDraw()他に必要がなくなった場合は、オーバーライドを削除できます。

于 2016-06-30T13:50:39.543 に答える