I have a HorizontalScrollView in which there are several views inside it. I implemented a pinch zoom gesture in which several views that are between two fingers are scaled.
But I faced one failure. When I do the scaling, the mid-point of the scaling increases, but for the convenience of the user, I want this point to remain fixed, and other things should be adjusted during scaling, so that the mid-point remains stationary.
Can someone tell me how to do this.
onDraw() custom view method
Rect r =new Rect(0, 0, 700, 40); public void onDraw(Canvas canvas) { float kk=mScaleFactor;
onMeasure method called on requestLayout
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension((int)width, 340); }
The above custom view is called 12 times a subclass of HorizontalScrollView . Thus, there are 12 child views of the HorizontalScrollView .
In this class I do the following things
Detection of touch coordinates of two fingers.
Calculation of the index of the child's view, which touched the first finger.
Calculation of the index of the child's view, which touched the second finger.
Transmission of the scale factor for all child views between the beginning and the last. These two indexes are calculated in the previous two steps.
And finally, invalidate () is called in the child view. Thus, the child can scale itself in accordance with the scaling factor transmitted by the parent representation.
But there is one problem. The midpoint of two fingers should remain motionless, and other things should be adjusted during scaling. But my midpoint moves with scaling.
Can someone help me with this. Please tell me if any part of the code is needed.
HorizontalScrollView Listening Code -
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScale(ScaleGestureDetector detector) { mScaleFactor *= detector.getScaleFactor(); mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f)); ViewGroup pp=takeparent();
Example of my application 
Editing as indicated in the comments:
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScale(ScaleGestureDetector detector) { mScaleFactor *= detector.getScaleFactor(); mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f)); ViewGroup pp=takeparent(); pp contains all the custom child views
This is a custom onDraw method.
public void onDraw(Canvas canvas) { sf=mScaleFactor //this scale factor is set by parent view width=sf*700; //this width will be use to rescale the view width in requestLayout() canvas.save(); canvas.scale(sf,1,pivotx,pivoty); //pivotX and pivotY are also set by parent onScale method of gestureListener canvas.drawRect(r, paint); requestLayout(); canvas.restore(); }
