question

njsokalski avatar image
0 Votes"
njsokalski asked RobCaplan edited

Waiting for Completed Layout Pass Before Scrolling

I have a horizontal RecyclerView, and I sometimes want a certain part of it to stay in view. However, when the user edits the data, a component to the left of the RecyclerView may change in width, therefore possibly causing the desired area to be partially offscreen. Here are 2 screenshots:94989-screenshot-1620513136.png95024-screenshot-1620513153.png
Notice that in the second screenshot, the black column on the left is wider, which has therefore pushed part of the orange column on the right offscreen. The values in the black column are dynamically updated as the values in the other columns are edited, so I need to be able to know when the black column is done updating. (NOTE: As you can probably guess, the black column is a RecyclerView, and the colored columns are items in a horizontal RecyclerView (the one I need to scroll)) How can I detect when the black RecyclerView is finished updating (when it changes size)?


dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

njsokalski avatar image
0 Votes"
njsokalski answered

I don't know if I am doing it the most efficient way, but after a little fooling around I managed to use the LayoutChange event to solve the problem. Thanks for your help!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

so I need to be able to know when the black column is done updating

The notify changed event doesn't have a callback method. To detect if the update is completed, try using async-await to wait for the method to be executed.

await Task.Run(async () => {
    this.RunOnUiThread(() =>
    {
        //update the list
        myadapter.NotifyItemChanged(list.Count);
    });
});


Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm not sure if your solution should solve my problem or not (maybe I'm just using it wrong), but when I tried to use it, it didn't help. "Updating" may have been the wrong term for me to use, because it is actually the layout (not the data) that I need to wait for. In my code, I manually calculate the width for the black column (so that I can set this.rvRoundNumbers.LayoutParameters.Width), and then call SmoothScrollToPosition on the RecyclerView that contains the colored columns. I think that SmoothScrollToPosition is miscalculating the scroll position because the layout has not finished updating. Is your solution supposed to have solved this problem? I've always had problems figuring out when layout is completed.

0 Votes 0 ·

Is your solution supposed to have solved this problem?

It's too fast to add the items. When executing the next line code, the items have been added. How do you check the result?

For this function, here is a similar issue which uses the onLayoutCompleted of LayoutManager to solve the problem. Please try to the method in your sample.
https://stackoverflow.com/questions/30397460/how-to-know-when-the-recyclerview-has-finished-laying-down-the-items/64351936#64351936

0 Votes 0 ·