Created
February 1, 2015 12:32
-
-
Save davemorrissey/9133860908fb4977644c to your computer and use it in GitHub Desktop.
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 CustomSubsamplingScaleImageView extends SubsamplingScaleImageView { | |
private final AtomicBoolean scaleSet = new AtomicBoolean(false); | |
public CustomSubsamplingScaleImageView(Context context, AttributeSet attr) { | |
super(context, attr); | |
setAlpha(0); | |
} | |
public void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
if (scaleSet.get()) { | |
setAlpha(1); | |
} | |
} | |
@Override | |
protected void onImageReady() { | |
post(new Runnable() { | |
@Override | |
public void run() { | |
float scale = Math.min(getWidth() / (float) getSWidth(), (getHeight() - (2 * 100)) / (float) getSHeight()); | |
setMinScale(scale); | |
setMinimumScaleType(SCALE_TYPE_CUSTOM); | |
setScaleAndCenter(scale, getCenter()); | |
postInvalidate(); | |
scaleSet.set(true); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment