网格视图中的Android水平滚动 [英] Android horizontal scroll in grid view

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

问题描述

我想实现一个水平网格视图,其中图像和所有其他描述将由服务器提供.

I want to implement a horizontal grid view where images and all other descriptions will be provided by a server.

我能够将图像放置在网格视图中,但是即使将网格视图放置在Horizo​​ntalScrollView中,它也可以垂直滚动.

I am able to put images inside a grid view but it is scrolling vertically even if I put my grid view inside a HorizontalScrollView.

其外观应为:左图,中心图,右图.如果有任何上一个或下一个图像,则该图像应在屏幕的左边缘和右边缘保持部分可见.向左或向右滚动时,下一张/上一张图像应移到中心.

It should look like: left image, center image, right image. If there is any previous or next image then that image should remain partially visible at the left and right edges of the screen. On scrolling left or right, the next/previous image should move to the center.

任何人都可以告诉我如何最好地实现这种行为而不使用第三方库吗?

Can any one tell me how best to implement this behavior without using a third party library?

推荐答案

我的建议是将GridView换成RecyclerView. RecyclerView + LayoutManager组合允许这种类型的布局更多种类.来自 RecyclerView.LayoutManager文档:

My suggestion would be to swap out the GridView for a RecyclerView. The RecyclerView + LayoutManager combination allows much more variety in layouts of this type. From the RecyclerView.LayoutManager documentation:

通过更改LayoutManager,可以使用RecyclerView来实现标准的垂直滚动列表,统一网格,交错网格,水平滚动集合等等.

By changing the LayoutManager a RecyclerView can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more.

您可能希望查看 GridLayoutManager 开始.我的猜测是构造函数中的orientation参数:

You would want to look at the GridLayoutManager to start with. My guess is that the orientation parameter in the constructor:

GridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout)

可以使您很容易地设置水平滚动.最糟糕的是,您可能必须进行一些自定义的触摸处理才能管理水平运动.

may allow you to set up horizontal scrolling quite easily. At worst, you may have to do some custom touch handling to manage horizontal motion.

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

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