adjustviewbounds functionality
See original GitHub issuewhat i am trying to achieve is the effect where my imageview would have a match_parent width and its height will adapt in order to preserve its aspect ratio.
this is my SimpleDraweeView
<com.facebook.drawee.view.SimpleDraweeView android:id=“@+id/categories_root_cell” android:background=“#ff0000” android:layout_width=“match_parent” android:layout_height=“wrap_content” android:contentDescription=“@string/c_generic_descr_image” fresco:actualImageScaleType=“fitCenter” fresco:placeholderImageScaleType=“fitCenter” />
i am also setting holder.categoriesImage.setAdjustViewBounds(true); in my adapters getview, where holder —> static class ViewHolder { @InjectView(R.id.categories_root_cell_image) SimpleDraweeView categoriesImage; @InjectView(R.id.categories_root_cell_text) TextView categoryTitle;
public ViewHolder(final View view) {
ButterKnife.inject(this, view);
}
}
what i get is this :
from what you have said i shouldnt have used setAdjustViewBounds as it is not supported (or it wont be supported in the future), but if i dont then the behaviour is even stranger and the image is not visible.
maybe i am missing something but i was able to achieve it before using SimpleDraweeView with this setup
<ImageView
android:id="@+id/categories_root_cell_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/c_generic_descr_image"/>
and the result is this
what it seems to be the problem is that adjustViewBounds functionality can not be supported. what is being done is that the image loaded itself gets resized correctly but the SimpleDraweeView doesnot get resized and keeps the original image’s height.
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (3 by maintainers)
Top GitHub Comments
The reason why
wrap_content
andadjustviewBounds
are not supported is explained in http://frescolib.org/docs/using-drawees-xml.html#_ If you absolutely need to achieve this functionality (even though it would not look pleasant to the users as the views will jump on screen as images start to arrive), you can do it as follows:In XML do:
In Java, instead of just setting the URI, you’ll have to build a controller and set both URI and a controller listener, like explained here: http://frescolib.org/docs/listening-download-events.html#_ In
onIntermediateImageSet
andonFinalImageSet
methods do this:Actually The best thing Frisco did is get rid of wrap content … it makes images jump in a recyclerview/listview and it confuses the user. My solution to this is that I get image height from my server and I set the width to matche parent and then I get screen width to find my image width as it is match parent (and getting rid of any vertical margins/padding around SimpleDraweeView in calculation) Then programmatically, I set the calculated height when I first populate SimpleDraweeView to the recyclerview and now all SimpleDraweeView in the recyclerview are in the size of the image they will receive before even getting the image (so all SimpleDraweeView aware of the size of the images they will load) , so no jumping issue and it works well. Just make sure to get screen width and if there are verical margins/paddings around your SimpleDraweeView or its list item, subtract them from screen width to get images actual width