mttkay / ignition

Kick-starts Android application development.
1.28k stars 289 forks source link

RemoteImageView subview no longer scales correctly #24

Open mgregson opened 12 years ago

mgregson commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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

mttkay commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

this should be fixed by 7a66e9a06b511bf4da1eb21141a17017dd3fd730

Can you please test this?

mgregson commented 12 years ago

Will test and let you know.

mttkay commented 12 years ago

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.