Android中的水平ListView? [英] Horizontal ListView in Android?
问题描述
是否可以使 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
优点:
- 由于使用 Recyclerview Adapter,ViewHolder 模式是自动实现
- 动画易于执行
- 更多功能
关于RecyclerView
的更多信息:
More Information about RecyclerView
:
示例:
只需添加下面的代码块即可使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屋!