在android系统回收视图水平和垂直滚动 [英] Horizontal and vertical scrolling in android recycler view

查看:203
本文介绍了在android系统回收视图水平和垂直滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我需要有水平滚动和垂直滚动的回收视图的要求。它是基于数据是从服务器传来的类型。如果来自服务器的响应是有第一个元素作为一个数组,我需要的是在一个水平滚动列表,如果第二个元素是一个单独的对象,那么我需要表现出来的卡。同样,订单变更,并应反映在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);

这篇关于在android系统回收视图水平和垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆