Skip to content

Commit 3c9345d

Browse files
committed
fixed positioning and scaling issues
positioning methods need explicit scaling; runtime scaling (not due to gestures) could cause View to scroll beyond visible limits - added constraint in layout pass to prevent this
1 parent 3891885 commit 3c9345d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/com/qozix/layouts/ZoomPanLayout.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.graphics.Rect;
99
import android.os.Handler;
1010
import android.os.Message;
11-
import android.support.v4.widget.ScrollerCompat;
1211
import android.util.Log;
1312
import android.view.MotionEvent;
1413
import android.view.VelocityTracker;
@@ -18,6 +17,7 @@
1817
import com.qozix.animation.Tween;
1918
import com.qozix.animation.TweenListener;
2019
import com.qozix.animation.easing.Strong;
20+
import com.qozix.widgets.Scroller;
2121

2222
/**
2323
* ZoomPanLayout extends ViewGroup to provide support for scrolling and zooming. Fling, drag, pinch and
@@ -85,7 +85,7 @@ public class ZoomPanLayout extends ViewGroup {
8585

8686
private ScrollActionHandler scrollActionHandler;
8787

88-
private ScrollerCompat scroller;
88+
private Scroller scroller;
8989
private VelocityTracker velocity;
9090

9191
private HashSet<GestureListener> gestureListeners = new HashSet<GestureListener>();
@@ -138,8 +138,8 @@ public ZoomPanLayout( Context context ) {
138138

139139
scrollActionHandler = new ScrollActionHandler( this );
140140

141-
scroller = ScrollerCompat.create( context );
142-
//scroller.setFriction( FRICTION );
141+
scroller = new Scroller( context );
142+
scroller.setFriction( FRICTION );
143143

144144
clip = new StaticLayout( context );
145145
super.addView( clip, -1, new LayoutParams(-1, -1) );
@@ -447,6 +447,7 @@ protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) {
447447
@Override
448448
protected void onLayout( boolean changed, int l, int t, int r, int b ) {
449449
clip.layout( 0, 0, clip.getMeasuredWidth(), clip.getMeasuredHeight() );
450+
constrainScroll();
450451
if ( changed ) {
451452
calculateMinimumScaleToFit();
452453
}
@@ -533,7 +534,7 @@ private void constrainScroll() { // TODO:
533534
Point limitScroll = new Point( currentScroll );
534535
constrainPoint( limitScroll );
535536
if ( !currentScroll.equals( limitScroll ) ) {
536-
scrollToPoint( currentScroll );
537+
scrollToPoint( limitScroll );
537538
}
538539
}
539540

src/com/qozix/tileview/TileView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ public double unscale( double value ) {
382382
*/
383383
public void moveTo( double x, double y ) {
384384
Point point = positionManager.translate( x, y );
385+
point.x *= getScale();
386+
point.y *= getScale();
385387
scrollToPoint( point );
386388
}
387389

@@ -392,6 +394,8 @@ public void moveTo( double x, double y ) {
392394
*/
393395
public void moveToAndCenter( double x, double y ) {
394396
Point point = positionManager.translate( x, y );
397+
point.x *= getScale();
398+
point.y *= getScale();
395399
scrollToAndCenter( point );
396400
}
397401

@@ -402,6 +406,8 @@ public void moveToAndCenter( double x, double y ) {
402406
*/
403407
public void slideTo( double x, double y ) {
404408
Point point = positionManager.translate( x, y );
409+
point.x *= getScale();
410+
point.y *= getScale();
405411
slideToPoint( point );
406412
}
407413

@@ -412,6 +418,8 @@ public void slideTo( double x, double y ) {
412418
*/
413419
public void slideToAndCenter( double x, double y ) {
414420
Point point = positionManager.translate( x, y );
421+
point.x *= getScale();
422+
point.y *= getScale();
415423
slideToAndCenter( point );
416424
}
417425

0 commit comments

Comments
 (0)