Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteImageView subview no longer scales correctly #24

Open
mgregson opened this issue Apr 21, 2012 · 7 comments
Open

RemoteImageView subview no longer scales correctly #24

mgregson opened this issue Apr 21, 2012 · 7 comments

Comments

@mgregson
Copy link

After downloading a recent update to the Android SDK, enabling the Google APIs, I find that images I load using RemoteImageView are no longer scaling as specified in the layout XML. Instead, the ImageView subview is centered within the RemoteImageView. (My images are smaller than the space I would like them to fill.)

@mgregson
Copy link
Author

Currently working around it with:

int vpad = icon.getPaddingTop() + icon.getPaddingBottom();
int hpad = icon.getPaddingLeft() + icon.getPaddingRight();
ViewGroup.LayoutParams p = icon.getLayoutParams();
icon.getImageView().setAdjustViewBounds(true);
icon.getImageView()
  .setLayoutParams(new FrameLayout.LayoutParams(p.width - hpad,
                                                                                         p.height - vpad,
                                                                                         0x77));

@mttkay
Copy link
Owner

mttkay commented Apr 23, 2012

Do you have sample code that I can use to reproduce the issue?

@mttkay
Copy link
Owner

mttkay commented Apr 23, 2012

I think I see what the issue is. This is not due to a recent SDK/tools update though, it's basically the same as issue #14.

This is because all view attributes from RemoteImageView are passed down to the underlying ImageView, since RIV just acts as a proxy. Doing this introduces its own set of issues though, such as duplicate view IDs, and as I found out just now, layout params being not correctly copied (the underlying ImageView has width/height set to wrap_content even when I specify specific values to RIV).

I'm not entirely sure yet how to fix that, since there is no way to only pass a subset of an AttributeSet to a view, or being able to manipulate an AttributeSet once inflated. Setting every single possible view attribute programmatically would be a tedious but possible way, however, not all ImageView attributes have a corresponding Java method if I remember correctly.

Suggestions welcome.

@mttkay
Copy link
Owner

mttkay commented Apr 23, 2012

Now that I think about it, another way could be to actually make RemoteImageView inherit from ImageView so that it actually becomes a proper ImageView (this would render the whole attribute issue null and void), and on inflation create its container (the view flipper) and the progress bar dynamically and have it re-insert itself into the view tree underneath the container. Not sure if that would work, but may be worth investigating.

@mttkay
Copy link
Owner

mttkay commented May 8, 2012

this should be fixed by 7a66e9a

Can you please test this?

@mgregson
Copy link
Author

mgregson commented May 9, 2012

Will test and let you know.

@mttkay
Copy link
Owner

mttkay commented May 9, 2012

Thanks Michael. Have a look at the changed sample app as well. Previously RemoteImageView didn't actually behave like a native ImageView (since it wasn't an ImageView, but a ViewSwitcher), so you may have to work on your layout attributes a little.

One instance I can think of is that wrap_content does not work well anymore, since there is no image at inflation time around which the view could wrap. Hence, make sure to always specify a pre-defined width and height, otherwise the result will be a view that suddenly grows in size once the image is loaded.

A good way to specify size is using Android's dimension resources e.g. layout_width="@dimen/expected_image_width"
Those can be scaled to different screen sizes using Android's resource mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants