SuReSh PaTi
SuReSh PaTi

Reputation: 1371

GridView scroll down and up when click on buttons?

I have a View with GridView and two Buttons(up and down) in it.Here when we click on down button gridview will be scroll down and click on up button gridview will scroll up.Is there any chance to do that.Please any one give guidance(or tutorial) to do that.please help me

Upvotes: 1

Views: 3860

Answers (2)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53667

You need to calculate the position of first image to be displayed and set that position in gridview using smoothScrollToPosition() if using api 8 or higher gridview.scrollTo(x, y) if using lower api

Step-1 get the first and last image position from greed view

Step-2 When user clicks down button stroe the selected position as last visible image position +1 When user clicks up button store the selected position as first visible image position -1 Step-3 set the image selection using and scroll the gridview by passing x and y co-ordinate of the image using gridview.scrollTo(x, y) for lower api and using smoothScrollToPosition(position) for api 8 or higher

Upvotes: 3

Alex Paino
Alex Paino

Reputation: 250

You should look into smoothScrollToOffset(int offset) and smoothScrollToPosition(int position), both of which are GridView functions.

I would recommend using smoothScrollToPosition(int position) since it takes as a parameter the position (in your adapter) of the view you want to scroll to. Presumably, you would know the position in your adapter of the place you want to scroll to.

Look here for reference: http://developer.android.com/reference/android/widget/GridView.html

Upvotes: 1

Related Questions