Kiradev
Kiradev

Reputation: 347

How to know image was translated or not with matrix?

I'm using TouchImageView from github and using matrix.posttranslate to handle user control of dragging zoom image. Problem is I need to know when user drag to border of image, so image can't move horizontally any more. Has anyone have ideal about that?

Upvotes: 0

Views: 145

Answers (2)

Kiradev
Kiradev

Reputation: 347

Thanks. And after deeply read sourcecode of gallery on github, i got solution. To check whether swipe to right border or not:

float scaledWidth = Math.round(mOrigWidth * mSaveScale);
                    if (Math.abs(mViewWidth - translateX - scaledWidth) <= 1.0) {
                        // drag to right border
                        ALog.d("touchimageview", "right x: "
                                + (mViewWidth - translateX - scaledWidth));
                        touchEventListener.onZoomToOriginal();
                        break;
                    }

Upvotes: 0

Vladimir Mironov
Vladimir Mironov

Reputation: 30884

If you are not rotating your Matrix then second and fifth elements are translateX and translateY:

    final Matrix matrix = ...;
    final float[] values = new float[9];

    matrix.getValues(values);

    final float translateX = values[2];
    final float translateY = values[5];

Upvotes: 1

Related Questions