Android中的水平ListView? [英] Horizontal ListView in Android?

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

问题描述

是否可以使 ListView 水平放置?我使用图库视图完成了此操作,但所选项目会自动出现在屏幕中央.我不希望在我单击的同一位置选择项目.我该如何解决这个问题?我的想法是用水平滚动设置 ListView .分享您的想法?

Is it possible to make the ListView horizontally? I have done this using a gallery view, but the selected item comes to the center of the screen automatically. I don't want the selected item at the same spot I clicked. How can I rectify this problem? My idea was to set the ListView with a horizontal scroll. Share your idea?

推荐答案

根据 Android 文档 RecyclerView 是一种在列表视图中组织项目并水平显示的新方法

As per Android Documentation RecyclerView is the new way to organize the items in listview and to be displayed horizontally

优点:

  1. 由于使用 Recyclerview Adapter,ViewHolder 模式是自动实现
  2. 动画易于执行
  3. 更多功能

关于RecyclerView的更多信息:

More Information about RecyclerView:

  1. grokkingandroid.com
  2. antonioleiva.com

示例:

survivingwithandroid.com

只需添加下面的代码块即可使ListView从垂直变为水平

Just add the below block to make the ListView to horizontal from vertical

代码片段

LinearLayoutManager layoutManager= new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(layoutManager);

这篇关于Android中的水平ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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