How to use RecyclerView inside NestedScrollView?

前端 未结 24 2419
抹茶落季
抹茶落季 2020-11-22 03:39

How to use RecyclerView inside NestedScrollView? RecyclerView content is not visible after setting adapter.

UPDATE

24条回答
  •  别跟我提以往
    2020-11-22 04:17

    If you are using RecyclerView-23.2.1 or later. Following solution will work just fine:

    In your layout add RecyclerView like this:

    
    

    And in your java file:

    RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    LinearLayoutManager layoutManager=new LinearLayoutManager(getContext());
    layoutManager.setAutoMeasureEnabled(true);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(new YourListAdapter(getContext()));
    

    Here layoutManager.setAutoMeasureEnabled(true); will do the trick.

    Check out this issue and this developer blog for more information.

提交回复
热议问题