question

njsokalski avatar image
0 Votes"
njsokalski asked RobCaplan edited

RecyclerView Acting Unexpectedly in Landscape

I have an Activity that contains a RecyclerView that is acting unexpectedly when the device is in Landscape. Here are screenshots of Portrait & Landscape (the RecyclerView is the green area):
100585-screenshot-1622257354.png

100586-screenshot-1622257366.png
In portrait, the RecyclerView lets me scroll and uses the expected area as in my xml layout file, but in landscape, it does not let me scroll and uses more area than expected (as you can see, it pushes the other View(s) of the screen). The number of elements in the RecyclerView is more than fit on screen for either orientation, yet only portrait resizes the RecyclerView. I also noticed (by using the Output window) that in portrait, OnBindViewHolder is only called for the visible items (8, which is what I would expect), but in landscape, it is being called for all the elements in the RecyclerView's Adapter (in this case, 11). I override both OnCreate & OnResume with the same code. Why is landscape causing these unexpected problems?

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.

1 Answer

JarvanZhang-MSFT avatar image
1 Vote"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

but in landscape, it does not let me scroll and uses more area than expected (as you can see, it pushes the other View(s) of the screen)

Hi, njsokalski. I created a basic demo to test the function, the recyclerView works fine when scrolling to landscape mode. How do you define the recylcerView? Could you please post the layou.xml about the Activity and the item layout? And What does 'uses more area than expected' mean? According to the screenshot, it seems the screen doesn't display the 'totals options' which may be because the landscape height.

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 think you may be right about the landscape height. I tried creating a separate layout for design (using the layout-land technique), and it seems good now. Thanks.

0 Votes 0 ·

Glad to hear that. Happy coding!

0 Votes 0 ·