1

ビューの要素を表示するスクロールビューを実装しています...スクロールをシフトするには、左右のボタンの 2 つのボタンで中央のビューをスクロールします

このシナリオでは、スクロール ビューからボタンにフォーカスを移したいと考えています。

誰もそれについて考えていますか?

4

1 に答える 1

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.
于 2016-02-08T09:58:09.157 に答える