NullPointerException in dissapearence animation of RecyclerView from support v.23.2.0

后端 未结 3 514
眼角桃花
眼角桃花 2021-01-05 18:09


In new RecyclerView we can use wrap_content for height (or for width). So Google fixed bug - https://code.google.com/p/android/issues/detail?id=74772

3条回答
  •  清酒与你
    2021-01-05 18:20

    I have exactly the same exception. It occurs when I add a view to the RecyclerView and that view is completely beyond the boundaries of the RecyclerView (user would have to scroll to see that newly added view).

    However, I've noticed that this exception only occurs when width or height of the RecyclerView is wrap_content or 0dp with weight set to 1 inside a LinearLayout... If I set the width and height to any other value except those two, i.e. 140dp, match_parent, then everything works fine.

    So, I've tried to trick the buggy framework and find a solution to set the width of my RecyclerView to be as big as there are space left inside my LinearLayout that contains the RecyclerView (width:0dp, weight:1 combination), so I wrapped the RecyclerView inside another LinearLayout with weight set to 1, and set my RecyclerView's width to match_parent, so it gets as wide as parent LinearLayout can get, and the parent LinearLayout fills the free space in another parent LinearLayout. And voila, it works perfectly!

    I know, it sounds ridiculous, but that's the way I worked it out...

    Here's the source code if anybody needs to get the idea of how to workaround this bug...

    
    
        
    
            
    
        
    
        

    The RecyclerView now is as wide as there are free space in the parent LinearLayout, which also contains one button to the right of the RecyclerView, and no crashes occurs.

    If anybody finds out the real cause of such an exception or a better way to fix it, please share...

提交回复
热议问题