-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,293 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/divyansh/tech/twodscrollablezoomable/CustomZoomScrollView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package divyansh.tech.twodscrollablezoomable; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.GestureDetector; | ||
import android.view.MotionEvent; | ||
import android.view.ScaleGestureDetector; | ||
import android.view.animation.ScaleAnimation; | ||
import android.widget.ScrollView; | ||
|
||
public class CustomZoomScrollView extends ScrollView { | ||
|
||
|
||
// step 1: add some instance | ||
private float mScale = 1f; | ||
private ScaleGestureDetector mScaleDetector; | ||
GestureDetector gestureDetector; | ||
|
||
|
||
public CustomZoomScrollView(Context context) { | ||
super(context); | ||
} | ||
|
||
public CustomZoomScrollView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
//step 2: create instance from GestureDetector(this step should be place into onCreate()) | ||
gestureDetector = new GestureDetector(getContext(), new GestureListener()); | ||
|
||
mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() { | ||
@Override | ||
public boolean onScale(ScaleGestureDetector detector) { | ||
float scale = 1 - detector.getScaleFactor(); | ||
|
||
float prevScale = mScale; | ||
mScale += scale; | ||
|
||
if (mScale < 0.1f) // Minimum scale condition: | ||
mScale = 0.1f; | ||
|
||
if (mScale > 10f) // Maximum scale condition: | ||
mScale = 10f; | ||
ScaleAnimation scaleAnimation = new ScaleAnimation(1f / prevScale, 1f / mScale, 1f / prevScale, 1f / mScale, detector.getFocusX(), detector.getFocusY()); | ||
scaleAnimation.setDuration(0); | ||
scaleAnimation.setFillAfter(true); | ||
getRootView().startAnimation(scaleAnimation); | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
} | ||
|
||
private class GestureListener extends GestureDetector.SimpleOnGestureListener { | ||
@Override | ||
public boolean onDown(MotionEvent e) { | ||
return true; | ||
} | ||
// event when double tap occurs | ||
@Override | ||
public boolean onDoubleTap(MotionEvent e) { | ||
// double tap fired. | ||
return true; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/divyansh/tech/twodscrollablezoomable/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package divyansh.tech.twodscrollablezoomable; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.widget.AppCompatImageView; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
AppCompatImageView iv = findViewById(R.id.image); | ||
TwoDScrollableZoomableView view = findViewById(R.id.scrollable); | ||
Glide.with(this).load("https://wallpaperaccess.com/full/391249.jpg").into(iv); | ||
} | ||
} |
Oops, something went wrong.