RecyclerView with Overlapping Items

Nathan Sokalski 4,111 Reputation points
2022-12-06T23:21:40.927+00:00

I have a RecyclerView with which I want the items to overlap. What I tried doing was setting the TranslationX property in OnBindViewHolder, however, this did not work because items that would have originally been offscreen were not rendered. If I do this manually using a single-cell GridLayout (rather than a RecyclerView), it works fine. What can I do to allow me to translate items that would initially be offscreen?

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-12-07T02:48:30.367+00:00

    Hello,

    On Andrid, you need to use RecyclerView.ItemDecoration to make your items in RecyclerView overlap.

    Please refer to the following code and documentation:

       public class MyDecotion : RecyclerView.ItemDecoration  
       {  
           public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)  
           {  
               base.GetItemOffsets(outRect, view, parent, state);  
               outRect.Bottom = -50;  
           }  
       }  
         
       rec.AddItemDecoration(new MyDecotion());  
    

    RecyclerView.ItemDecoration-getItemOffsets

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.