在android系统回收视图水平和垂直滚动视图、系统、水平和、android

2023-09-07 08:43:42 作者:孤傲是一种态度

我有,我需要有水平滚动和垂直滚动的回收视图的要求。它是基于数据是从服务器传来的类型。如果来自服务器的响应是有第一个元素作为一个数组,我需要的是在一个水平滚动列表,如果第二个元素是一个单独的对象,那么我需要表现出来的卡。同样,订单变更,并应反映在UI中。我怎样才能做到这一点。

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. How can I achieve this.

推荐答案

LayoutManager的是,布局RecyclerView意见的类。因此,改变recyclerView.setLayoutManager(LayoutManager的),如果你想改变布局。在你的情况,如果你使用LinearLayoutManager,通过调用做到这一点:

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(LinearLayoutManager.HORIZONTAL);

//when you want vertical
layoutManager.serVertical(LinearLayoutManager.VERTICAL);