Mayank Mahajan
Mayank Mahajan

Reputation: 21

How to bring an image in the center of horizontal scroll view?

I have a horizontal scroll view placed below a map The map has some markers and the horizontal scroll view contains images for each of the markers.

Now, when ever user clicks a maker,I want the horizontal view to scroll and image for that marker to come to the center. This could have been a bit easier with the gallery view, but since that has been deprecated, how shall I go about it now?

Upvotes: -1

Views: 673

Answers (3)

Scott
Scott

Reputation: 1922

Use android:gravity="center" in your layout.xml file to center all the images in the scrollView.

Use yourScrollView.scrollTo(x,y) to automatically select the relevant image.

Upvotes: 0

Teo Inke
Teo Inke

Reputation: 5986

If I understood your question, you want to manually scroll your ScrollView to a specific position.

You should use the scrollTo() method to perform that. Take a look at this question which has an example.

Upvotes: 0

Rik
Rik

Reputation: 519

android:gravity="center"

post that in the xml

Upvotes: 0

Related Questions