如何建立一个水平的ListView与RecyclerView? [英] How to build a Horizontal ListView with RecyclerView?

查看:91
本文介绍了如何建立一个水平的ListView与RecyclerView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现我的Andr​​oid应用水平列表视图。我做了一些研究和碰到<一href="http://stackoverflow.com/questions/3877040/how-can-i-make-a-horizontal-listview-in-android">How我可以做一个横向的ListView的机器人?和在Android的水平的ListView?但是的这些问题被问过Recyclerview被释放。有没有更好的办法,现在实现这个与Recyclerview?

解决方案
  

有没有更好的办法,现在实现这个与Recyclerview现在?

是的。

当你使用 RecyclerView ,你需要指定一个布局管理,负责铺设中的每个项目风景。该<一href="https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html"><$c$c>LinearLayoutManager允许你指定一个方向,就像一个正常的的LinearLayout 会。

要创建水平列表 RecyclerView ,你可能会做这样的事情:

  LinearLayoutManager的layoutManager
    =新LinearLayoutManager(这一点,LinearLayoutManager.HORIZONTAL,假);

RecyclerView myList上=(RecyclerView)findViewById(R.id.my_recycler_view);
myList.setLayoutManager(的layoutManager);
 

I need to implement a horizontal listview in my Android application. I did a bit of research and came across How can I make a horizontal ListView in Android? and Horizontal ListView in Android? however, these questions were asked before Recyclerview was released. Is there a better way to implement this now with Recyclerview?

解决方案

Is there a better way to implement this now with Recyclerview now?

Yes.

When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would.

To create a horizontal list with RecyclerView, you might do something like this:

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);

这篇关于如何建立一个水平的ListView与RecyclerView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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