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

Horizontal and vertical scrolling in android recycler view(android回收器视图中的水平和垂直滚动)

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

问题描述

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 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);

这篇关于android回收器视图中的水平和垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:android回收器视图中的水平和垂直滚动

基础教程推荐