question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

adjustviewbounds functionality

See original GitHub issue

what 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 :

screenshot_2015-04-21-10-41-37

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

screenshot_2015-04-21-11-53-53

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:closed
  • Created 8 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
plamenkocommented, Apr 21, 2015

The reason why wrap_content and adjustviewBounds 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:

android:layout_width="match_parent"
android:layout_height="0dp"

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 and onFinalImageSet methods do this:

mSimpleDraweeView.setAspectRatio((float) imageInfo.getWidth() / imageInfo.getHeight());
0reactions
abdulelahragihcommented, Nov 16, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android ImageView AdjustViewBounds Demystified | by Elye
When AdjustViewBounds is set to true for MatchParent images, it will then ensure the image is fit into the View, and maintain the...
Read more >
Correct the ImageView's adjustViewBounds behaviour on API ...
I want to scale up an ImageView proportionally to fit its parent. How can I do that · ImageView · layout_width · "match_parent"...
Read more >
ImageView - Android Developers
android:adjustViewBounds, Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
Read more >
A guide for Android ImageView ScaleType and ...
adjustViewBounds to the rescue. Fortunately there is a really simple way to preserve the aspect ratio of the image while keeping control of...
Read more >
android - adjustViewBounds analogue in Jetpack Compose
I don't think that something like adjustViewBounds is currently ... for better reusability and readability we can wrap it in a function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found