How to put RecyclerView inside NestedScrollView?

后端 未结 4 1541
南方客
南方客 2020-11-30 18:30

With creation of NestedScrollView you can put scrolling view inside another scrolling view as long as those implement NestedScrollingChild and NestedScrollingParent correctl

4条回答
  •  感动是毒
    2020-11-30 19:04

    So put RecyclerView inside NestedScrollView directly will unfortunately display nothing. However, there is a way to put the recyclerview inside the NestedScrollView indirectly - just use a frameLayout as the third party to hold your recyclerview.

    This is the framelayout which holds the nested recyclerview in your activity class:

        
    
            
            
       
    

    Put your fragment into the framelayout (code sits within the activity class):

     ExampleFragment exampleFragment = new ExampleFragment();
    
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.container, exampleFragment);
        ft.commit();
    

    In your exampleFragment, you can then put your recyclerview.

    
        
    
                
                
    
    
        
    

    This is the fragment code:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    
        super.onCreateView(inflater, container, savedInstanceState);
                llLayout = (RelativeLayout) inflater.inflate(R.layout.example_fragment_layout, container, false);
                        mRecyclerView = (RecyclerView) llLayout.findViewById(R.id.my_recycler_view);
    

    The following is the CheeseSquare XML layout you should have:

    
    
        
    
            
    
                
    
                
    
            
    
        
    
       
    
            
            
       
    
        
    
    
    

提交回复
热议问题