Support RecyclerView doesn't show anything until touched

前端 未结 9 1978
后悔当初
后悔当初 2021-02-04 23:41

I\'m using the support RecyclerView in my app, and I see the most bizarre thing. It doesn\'t display any items until I touch to scroll. Then, all of a sudden, the RecyclerView p

9条回答
  •  耶瑟儿~
    2021-02-05 00:26

    This is a bit late, but in my case I had a recylerview inside a viewpager (TabView) that was inside another viewpager (using BottomNavigationView) and smooth scrolling didn't change anything.

    However, I noticed that I had the recylerview set with Visibility GONE when the layout was drawn, so the solution was:

    1. Setting the recyclerview to Visibility VISIBLE on xml layout (so it's draw completely when the TabView is set);
    2. When the adapter is set (linked to observable with room), i do:
    new Handler(Looper.getMainLooper()).postDelayed(() -> {
    
         binding.recyclerView.scrollToPosition(0);
    
    }, getResources().getInteger(android.R.integer.config_shortAnimTime));
    
    

提交回复
热议问题