Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

Android horizontal scroll in grid view

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...