Created
September 9, 2012 13:56
-
-
Save kingori/3684472 to your computer and use it in GitHub Desktop.
https://github.com/TheDimasig/ImageViewZoom 의 full screen 버전: 최소 축소해도 화면을 꽉 채우도록
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
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