상속: Android.Views.ViewGroup
예제 #1
0
        public SlidingMenu(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            var behindParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            _viewBehind = new CustomViewBehind(context);
            AddView(_viewBehind, behindParams);

            var aboveParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            _viewAbove = new CustomViewAbove(context);
            AddView(_viewAbove, aboveParams);

            _viewAbove.CustomViewBehind = _viewBehind;
            _viewBehind.CustomViewAbove = _viewAbove;

            _viewAbove.PageSelected += (sender, args) =>
            {
                if (args.Position == 0 && null != Open)     //position open
                {
                    Open(this, EventArgs.Empty);
                }
                else if (args.Position == 2 && null != Close)     //position close
                {
                    Close(this, EventArgs.Empty);
                }
            };

            _viewAbove.Opened += (sender, args) => { if (null != Opened)
                                                     {
                                                         Opened(sender, args);
                                                     }
            };
            _viewAbove.Closed += (sender, args) => { if (null != Closed)
                                                     {
                                                         Closed(sender, args);
                                                     }
            };

            var a    = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingMenu);
            var mode = a.GetInt(Resource.Styleable.SlidingMenu_mode, (int)MenuMode.Left);

            Mode = (MenuMode)mode;

            var viewAbove = a.GetResourceId(Resource.Styleable.SlidingMenu_viewAbove, -1);

            if (viewAbove != -1)
            {
                SetContent(viewAbove);
            }
            else
            {
                SetContent(new FrameLayout(context));
            }

            TouchModeAbove  = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeAbove, (int)TouchMode.Margin);
            TouchModeBehind = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeBehind, (int)TouchMode.Margin);

            var offsetBehind = (int)a.GetDimension(Resource.Styleable.SlidingMenu_behindOffset, -1);
            var widthBehind  = (int)a.GetDimension(Resource.Styleable.SlidingMenu_behindWidth, -1);

            if (offsetBehind != -1 && widthBehind != -1)
            {
                throw new ArgumentException("Cannot set both behindOffset and behindWidth for SlidingMenu, check your XML");
            }
            if (offsetBehind != -1)
            {
                BehindOffset = offsetBehind;
            }
            else if (widthBehind != -1)
            {
                BehindWidth = widthBehind;
            }
            else
            {
                BehindOffset = 0;
            }

            var shadowRes = a.GetResourceId(Resource.Styleable.SlidingMenu_shadowDrawable, -1);

            if (shadowRes != -1)
            {
                ShadowDrawableRes = shadowRes;
            }

            BehindScrollScale = a.GetFloat(Resource.Styleable.SlidingMenu_behindScrollScale, 0.33f);
            ShadowWidth       = ((int)a.GetDimension(Resource.Styleable.SlidingMenu_shadowWidth, 0));
            FadeEnabled       = a.GetBoolean(Resource.Styleable.SlidingMenu_fadeEnabled, true);
            FadeDegree        = a.GetFloat(Resource.Styleable.SlidingMenu_fadeDegree, 0.33f);
            SelectorEnabled   = a.GetBoolean(Resource.Styleable.SlidingMenu_selectorEnabled, false);
            var selectorRes = a.GetResourceId(Resource.Styleable.SlidingMenu_selectorDrawable, -1);

            if (selectorRes != -1)
            {
                SelectorDrawable = selectorRes;
            }

            a.Recycle();
        }
예제 #2
0
        public SlidingMenu(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            var behindParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            _viewBehind = new CustomViewBehind(context);
            AddView(_viewBehind, behindParams);

            var aboveParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            _viewAbove = new CustomViewAbove(context);
            AddView(_viewAbove, aboveParams);

            _viewAbove.CustomViewBehind = _viewBehind;
            _viewBehind.CustomViewAbove = _viewAbove;

            _viewAbove.PageSelected += (sender, args) =>
                {
                    if (args.Position == 0 && null != Open) //position open
                        Open(this, EventArgs.Empty);
                    else if (args.Position == 2 && null != Close) //position close
                        Close(this, EventArgs.Empty);
                };
            _viewAbove.Opened += (sender, args) => { if (null != Opened) Opened(sender, args); };
            _viewAbove.Closed += (sender, args) => { if (null != Closed) Closed(sender, args); };
            _viewAbove.PageScrolled += (sender, args) => { if (null != PageScrolled) PageScrolled (sender, args); };

            var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingMenu);
            var mode = a.GetInt(Resource.Styleable.SlidingMenu_mode, (int) MenuMode.Left);
            Mode = (MenuMode) mode;

            var viewAbove = a.GetResourceId(Resource.Styleable.SlidingMenu_viewAbove, -1);
            if (viewAbove != -1)
                SetContent(viewAbove);
            else
                SetContent(new FrameLayout(context));

            TouchModeAbove = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeAbove, (int)TouchMode.Margin);
            TouchModeBehind = (TouchMode)a.GetInt(Resource.Styleable.SlidingMenu_touchModeBehind, (int)TouchMode.Margin);

            var offsetBehind = (int) a.GetDimension(Resource.Styleable.SlidingMenu_behindOffset, -1);
            var widthBehind = (int) a.GetDimension(Resource.Styleable.SlidingMenu_behindWidth, -1);
            if (offsetBehind != -1 && widthBehind != -1)
                throw new ArgumentException("Cannot set both behindOffset and behindWidth for SlidingMenu, check your XML");
            if (offsetBehind != -1)
                BehindOffset = offsetBehind;
            else if (widthBehind != -1)
                BehindWidth = widthBehind;
            else
                BehindOffset = 0;

            var shadowRes = a.GetResourceId(Resource.Styleable.SlidingMenu_shadowDrawable, -1);
            if (shadowRes != -1)
                ShadowDrawableRes = shadowRes;

            BehindScrollScale = a.GetFloat(Resource.Styleable.SlidingMenu_behindScrollScale, 0.33f);
            ShadowWidth = ((int)a.GetDimension(Resource.Styleable.SlidingMenu_shadowWidth, 0));
            FadeEnabled = a.GetBoolean(Resource.Styleable.SlidingMenu_fadeEnabled, true);
            FadeDegree = a.GetFloat(Resource.Styleable.SlidingMenu_fadeDegree, 0.33f);
            SelectorEnabled = a.GetBoolean(Resource.Styleable.SlidingMenu_selectorEnabled, false);
            var selectorRes = a.GetResourceId(Resource.Styleable.SlidingMenu_selectorDrawable, -1);
            if (selectorRes != -1)
                SelectorDrawable = selectorRes;

            a.Recycle();
        }