Search code examples
androidandroid-imageviewandroid-scrollview

How to slide to imageView in ScrollView


I have a layout in which i have two button:

1)back
2)help

and ScollView in which i place two image Views:

1) firstImageVeiw
1) SecondImageVeiw

first image View will be displayed on front and second is placed beneath the 1st image. Now i want that if i click on help button the the scrollView automatically slides to 2nd image view.

Any help or suggestion.


Solution

  • You can use scrollview's scrollTo() method

    helpbutton.setOnClickListener(new OnClickListener() {
       @Override
       public void onClick(View v) {
         yourscrollview.scrollTo(0, yourImageView.getTop());
       }
      });
    

    At runtime you can get the location of every view object with