2

I implement scroll view to display element of view...Scroll view in center with two button on left and right button to shift scroll

now in this scenario I want to shift focus from scroll view to button.

does any one have idea about it?

CoDe
  • 11,056
  • 14
  • 90
  • 197

1 Answers1

1

Option I: Using getLocationOnScreen on all Child Views inside ScrollView

  1. Get instance of scroll view.

    ScrollView scrollView = findViewById(R.id.scrollViewID);

  2. Type cast into ViewGroup

    ViewGroup viewGroup = (ViewGroup)scrollView;

  3. Find all child views of ViewGroup ( check Android Documentation )

    Get rectangle representing location of Child View on screen by calling - getLocationOnScreen

    getLocationOnScreen will store x,y coordinates in Rect object, compare rect x,y coordinates to see if Rectangles lies within screen bounds. ( You can get screen by using getLocationOnScreen on Content View / Root View )

Option II: getGlobalVisibleRect on All child views inside ScrollView ( Quick and Easy )

  1. Get all child views inside ScrollView. Call getGlobalVisibleRect on each of the child views, if it returns true, it means at-least some of portion of the child view is visible.
Pradeep
  • 6,303
  • 9
  • 36
  • 60