Horizontal and vertical scrolling in android recycler view

前端 未结 1 508
难免孤独
难免孤独 2021-01-13 05:00

I have a requirement where I need to have horizontal scrolling and vertical scrolling in a recycler view. It is based on the type of data that is coming from server. If the

1条回答
  •  走了就别回头了
    2021-01-13 05:44

    LayoutManager is the class that layout views in RecyclerView. So change recyclerView.setLayoutManager(LayoutManager) if you want to change layout. In your case, if you use LinearLayoutManager, do this by calling:

    LinearLayoutManager layoutManager = ...
    recyclerView.setLayoutManager(layoutManager);
    
    //when you want horizontal
    layoutManager.setOrientation(context, LinearLayoutManager.HORIZONTAL);
    
    //when you want vertical
    layoutManager.setOrientation(context, LinearLayoutManager.VERTICAL);
    

    0 讨论(0)
提交回复
热议问题