visual indication of over scroll in android

后端 未结 8 546
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 01:49

I am trying to add some visual indication, that there are no more pages in the desired fling direction in the ViewPager. However I am struggling to find a place, where to put re

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 02:22

    You can overload the setUserVisibleHint(boolean) function in your fragments. Pseudo code:

        void setUserVisibleHint(boolean isVisibleToUser) {
            // If this fragment is becoming visible
            if (isVisibleToUser == true) {
                 // Check if it is the last fragment in the viewpager
                 if (indexOfThis == getActivity().indexOfLast) {
                    // Display right limit reached
                    Toast(..., "No more Frags to right",...)
                    }
                 // Check if it is the first fragment in the viewpager
                 else if (indexOfThis == getActivity().indexOfFirst) {
                    // Display Left Limit reached
                    Toast(..., "No more Frags to left",...)
                 }
            }
        }
    

    I have not used this function for this purpose, but have used it for other reasons and it does fire appropriately. Hope this helps...

提交回复
热议问题