Exemplo n.º 1
0
        protected bool CanScroll(View view, bool checkV, int dx, int x, int y)
        {
            var viewGroup = view as ViewGroup;

            if (viewGroup == null)
            {
                return(checkV && ViewCompat.CanScrollHorizontally(view, -dx));
            }

            var scrollX = viewGroup.ScrollX;
            var scrollY = viewGroup.ScrollY;
            var count   = viewGroup.ChildCount;

            for (var i = count - 1; i >= 0; i--)
            {
                var child = viewGroup.GetChildAt(i);
                if (x + scrollX >= child.Left && x + scrollX < child.Right &&
                    y + scrollY >= child.Top && y + scrollY < child.Bottom &&
                    CanScroll(child, true, dx, x + scrollX - child.Left, y + scrollY - child.Top))
                {
                    return(true);
                }
            }
            return(checkV && ViewCompat.CanScrollHorizontally(view, -dx));
        }
        /// <summary>
        /// Tests scrollability within child views of v given a delta of dx.
        /// </summary>
        /// <param name="v"> View to test for horizontal scrollability </param>
        /// <param name="checkV"> Whether the view v passed should itself be checked for scrollability (true),
        ///               or just its children (false). </param>
        /// <param name="dx"> Delta scrolled in pixels </param>
        /// <param name="x"> X coordinate of the active touch point </param>
        /// <param name="y"> Y coordinate of the active touch point </param>
        /// <returns> true if child views of v can be scrolled by delta of dx. </returns>
        protected bool CanScroll(View v, bool checkV, int dx, int x, int y)
        {
            if (v is ViewGroup)
            {
                ViewGroup group   = (ViewGroup)v;
                int       scrollX = v.ScrollX;
                int       scrollY = v.ScrollY;
                int       count   = group.ChildCount;
                // Count backwards - let topmost views consume scroll distance first.
                for (int i = count - 1; i >= 0; i--)
                {
                    View child = group.GetChildAt(i);
                    if (x + scrollX >= child.Left && x + scrollX < child.Right && y + scrollY >= child.Top && y + scrollY < child.Bottom && CanScroll(child, true, dx, x + scrollX - child.Left, y + scrollY - child.Top))
                    {
                        return(true);
                    }
                }
            }

            return(checkV && ViewCompat.CanScrollHorizontally(v, -dx));
        }