How to horizontally zoom a HorizontalScrollView which scrolls both Vertically and Horizontally

15 views Asked by At

I have a custom HorizontalScrollView Which I am able to scroll both Vertically and Horizontally,

I want to zoom it Horizontally

public class MyHorizontalScrollView extends HorizontalScrollView {

    private Paint mPaint;
    private boolean isBanEvent;

    public MyHorizontalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (isBanEvent){
            return false;
        }
        return super.dispatchTouchEvent(ev);
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.WHITE);
        mPaint.setStrokeWidth(10);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
    }


    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        canvas.drawLine(getWidth() / 2 + getScrollX(), 0, getWidth() / 2 + getScrollX(), canvas.getHeight(), mPaint);
    }


    public void scrollToPosition(int x, int y) {
        ObjectAnimator xTranslate = ObjectAnimator.ofInt(this, "scrollX", x);
        ObjectAnimator yTranslate = ObjectAnimator.ofInt(this, "scrollY", y);
        AnimatorSet animators = new AnimatorSet();
        animators.setDuration(200L);
        animators.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                isBanEvent = true;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                isBanEvent = false;
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                isBanEvent = false;
            }
        });
        animators.playTogether(xTranslate, yTranslate);
        animators.start();
    }
}

How can we do this.

0

There are 0 answers