ignition icon indicating copy to clipboard operation
ignition copied to clipboard

RemoteImageView subview no longer scales correctly

Open mgregson opened this issue 13 years ago • 7 comments

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 avatar Apr 21 '12 17:04 mgregson

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));

mgregson avatar Apr 21 '12 18:04 mgregson

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

mttkay avatar Apr 23 '12 09:04 mttkay

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 avatar Apr 23 '12 10:04 mttkay

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 avatar Apr 23 '12 10:04 mttkay

this should be fixed by 7a66e9a06b511bf4da1eb21141a17017dd3fd730

Can you please test this?

mttkay avatar May 08 '12 16:05 mttkay

Will test and let you know.

mgregson avatar May 09 '12 00:05 mgregson

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.

mttkay avatar May 09 '12 07:05 mttkay