简体   繁体   English

android回收站视图中的水平和垂直滚动

[英]Horizontal and vertical scrolling in android recycler view

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 response from server is having first element as an array, i need that to be in a horizontal scrolling list and if the second element is a single object, then i need to show it in card. 如果来自服务器的响应将第一个元素作为数组,我需要将其放在水平滚动列表中,如果第二个元素是单个对象,那么我需要在卡片中显示它。 Similarly the order changes and should reflect in the UI. 同样,订单也会发生变化,应该反映在UI中。 How can I achieve this. 我怎样才能做到这一点。

LayoutManager is the class that layout views in RecyclerView . LayoutManagerRecyclerView中布局视图的类。 So change recyclerView.setLayoutManager(LayoutManager) if you want to change layout. 因此,如果要更改布局,请更改recyclerView.setLayoutManager(LayoutManager) In your case, if you use LinearLayoutManager , do this by calling: 在您的情况下,如果您使用LinearLayoutManager ,请通过调用:

LinearLayoutManager layoutManager = ...
recyclerView.setLayoutManager(layoutManager);

//when you want horizontal
layoutManager.setOrientation(context, LinearLayoutManager.HORIZONTAL);

//when you want vertical
layoutManager.setOrientation(context, LinearLayoutManager.VERTICAL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM