Skip to content

Instantly share code, notes, and snippets.

@davemorrissey
Created February 1, 2015 12:32
Show Gist options
  • Save davemorrissey/9133860908fb4977644c to your computer and use it in GitHub Desktop.
Save davemorrissey/9133860908fb4977644c to your computer and use it in GitHub Desktop.
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