Пример #1
0
        public override bool OnLayoutChild(
            CoordinatorLayout parent, Java.Lang.Object childObject, int layoutDirection)
        {
            Debug.WriteLineIf(DebugTrace, $"OnLayoutChild");
            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            if (ViewCompat.GetFitsSystemWindows(parent) && !ViewCompat.GetFitsSystemWindows(child))
            {
                ViewCompat.SetFitsSystemWindows(child, true);
            }
            int savedTop = child.Top;

            // First let the parent lay it out
            parent.OnLayoutChild(child, layoutDirection);
            // Offset the bottom sheet
            mParentHeight = parent.Height;
            mMinOffset    = Math.Max(0, mParentHeight - child.Height);
            mMaxOffset    = Math.Max(mParentHeight - mPeekHeight, mMinOffset);
            mAnchorOffset = (int)Math.Max(mParentHeight * mAnchorThreshold, mMinOffset);

            Debug.WriteLineIf(DebugTrace, $"offset computed => savedTop:{savedTop} mMinOffset:{mMinOffset} mMaxOffset:{mMaxOffset} mAnchorOffset:{mAnchorOffset} ");
            if (mState == STATE_EXPANDED)
            {
                ViewCompat.OffsetTopAndBottom(child, mMinOffset);
            }
            else if (mState == STATE_ANCHOR)
            {
                ViewCompat.OffsetTopAndBottom(child, mAnchorOffset);
            }
            else if (mHideable && mState == STATE_HIDDEN)
            {
                ViewCompat.OffsetTopAndBottom(child, mParentHeight);
            }
            else if (mState == STATE_COLLAPSED)
            {
                ViewCompat.OffsetTopAndBottom(child, mMaxOffset);
            }
            else if (mState == STATE_DRAGGING || mState == STATE_SETTLING)
            {
                ViewCompat.OffsetTopAndBottom(child, savedTop - child.Top);
            }
            if (mViewDragHelper == null || mViewDragHelper.Handle == IntPtr.Zero)
            {
                mViewDragHelper = ViewDragHelper.Create(parent, mDragCallback);
            }
            mViewRef = new WeakReference <View>(child);
            mNestedScrollingChildRef = new WeakReference <View>(findScrollingChild(child));
            return(true);
        }
 /**
  * 强制rootView下面的子View的FitsSystemWindows为false
  */
 public static void forceFitsSystemWindows(ViewGroup viewGroup)
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
     {
         int count = viewGroup.ChildCount;// GetChildCount();
         for (int i = 0; i < count; i++)
         {
             View view = viewGroup.GetChildAt(i);
             if (view is ViewGroup)
             {
                 forceFitsSystemWindows((ViewGroup)view);
             }
             else
             {
                 if (ViewCompat.GetFitsSystemWindows(view))
                 {
                     view.SetFitsSystemWindows(false);
                     //ViewCompat.SetFitsSystemWindows(view, false);
                 }
             }
         }
     }
 }