Skip to content

Instantly share code, notes, and snippets.

@douzifly
Created May 11, 2015 08:24
Show Gist options
  • Save douzifly/7fa56b3857bc08c9a6ed to your computer and use it in GitHub Desktop.
Save douzifly/7fa56b3857bc08c9a6ed to your computer and use it in GitHub Desktop.
relayout ImageView with image size after image donwloaded
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.test_dialog);
RecyclingImageView imageView = (RecyclingImageView) dialog.findViewById(R.id.dialog_header);
String url = "http://x.png";
DisplayImageOptions opts = RecyclingImageView.cloneDefaultOption();
opts.imageScaleType = ImageScaleType.NONE;
opts.displayer = new BitmapDisplayer() {
@Override
public void display(RecyclingBitmapDrawable bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
ViewGroup.LayoutParams lp = imageAware.getWrappedView().getLayoutParams();
int viewWidth = imageAware.getWidth();
int viewHeight = (int) ((float)(bitmap.getBitmap().getHeight()) / bitmap.getBitmap().getWidth() *
viewWidth);
lp.width = viewWidth;
lp.height = viewHeight;
imageAware.getWrappedView().requestLayout();
imageAware.setImageBitmap(bitmap);
}
};
imageView.loadUrl(url, opts);
dialog.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment