Skip to content

Instantly share code, notes, and snippets.

@kingori
Created September 9, 2012 13:56
Show Gist options
  • Save kingori/3684472 to your computer and use it in GitHub Desktop.
Save kingori/3684472 to your computer and use it in GitHub Desktop.
https://github.com/TheDimasig/ImageViewZoom 의 full screen 버전: 최소 축소해도 화면을 꽉 채우도록
public class FullScreenImageViewTouch extends ImageViewTouch {
public FullScreenImageViewTouch(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setImageDrawable(Drawable drawable) {
Point p = getScreenSize(getContext());
int bitmapWidth = drawable.getIntrinsicWidth();
int bitmapHeight = drawable.getIntrinsicHeight();
float minZoom = -1F;
if( bitmapWidth * p.y > bitmapHeight * p.x) {
minZoom = p.x / bitmapWidth;
} else {
minZoom = p.y / bitmapHeight;
}
if( minZoom < 0.9F) {
minZoom = 0.9F;
}
setMinZoom(minZoom);
setImageDrawable(drawable, true, null, minZoom * 3);
zoomTo(minZoom, 3f);
}
private static Point screenSize = null;
private static synchronized Point getScreenSize(Context ctx) {
if (screenSize == null) {
Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point point = new Point();
if (getApiVersion() >= 13) {
display.getSize(point);
} else {
point.y = display.getHeight();
point.x = display.getWidth();
}
screenSize = point;
}
return screenSize;
}
private static int getApiVersion() {
return Build.VERSION.SDK_INT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment