How to get actual view size before onBindViewHolder() in Recyclerview
See original GitHub issuei’m loading some big image in a recyclerview. i wanna resize it before it set to a SimpleDraweeView. Question is i can not get the actual view size before that. My item view layout is:
<***.SquaredFrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</***.SquaredFrameLayout>
the SquaredFrameLayout
is a squared layout base on it’s width
My adapter is like:
@Override
public void onBindViewHolder(@NonNull List<Object> items, int position,
@NonNull ViewHolder holder) {
FeedViewHolder viewHolder = (FeedViewHolder) holder;
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(URI1)
.setResizeOptions(new ResizeOptions(*, *))
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setOldController(viewHolder.mSimpleDraweeView.getController())
.build();
viewHolder.mSimpleDraweeView.setController(controller);
}
I cannot get size just like view.getWidth()
orview.getLayoutParams().width
.
it will return 0
How can I get actual view size before onBindViewHolder()
??
Thanks for your help!!!
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to get the height of recyclerview item in ... - Stack Overflow
With the addOnGlobalLayoutListener() method, the height value is obtained before the TextView is drawn. And then save it in a member variable.
Read more >Everything You Should Know To Create A Recyclerview
1. Item Click Listener · android:id="@+id/layout". After that, we will add it to Viewholder as below. · RelativeLayout layout;//Inside Constructor
Read more >Android Fundamentals: Working with the RecyclerView ...
Often, I see many examples which use the adapter's onBindViewHolder() method to do the work on the view holder. As I mentioned earlier,...
Read more >Android RecyclerView Tutorial with Kotlin - RayWenderlich.com
In this Android RecyclerView tutorial, learn how to use Kotlin to display datasets of a large or unknown size!
Read more >RecyclerView.Adapter - Android Developers
Most of the time, this is a case where the transient state will be cleared in onBindViewHolder call when View is rebound to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suggest you do as @gokhanbarisaker suggested and pass the width into the adapter.
Also, when someone tries to help you I don’t think responding “NONONONO!” is really going to encourage them to help you again in the future.
itemView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int width = itemView.getMeasuredWidth(); int height = itemView.getMeasuredHeight();