Example #1
0
        private void Initialize()
        {
            Element.Circle_r = DensityUtil.Dp2px(Context, 3f);
            Element.Circle_R = DensityUtil.Dp2px(Context, 20f);
            Element.Distance = DensityUtil.Dp2px(Context, 40f);
            var Length    = 3 * Element.Circle_R * 2 + Element.Distance * 2;
            int MyWidth   = DensityUtil.Dp2px(Context, (float)Element.WidthRequest);
            int MyPadding = (int)((MyWidth - Length) / 2);

            Element.X_Zero = MyPadding + Element.Circle_R;
            Element.Y_Zero = MyPadding + Element.Circle_R;
            paint          = new Paint();
            SetOnTouchListener(this);
            Element.InitPointList();
            PostInvalidate();
        }
Example #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_practice_weibo);

            mToolbar = FindViewById <Toolbar>(Resource.Id.toolbar);
            mToolbar.NavigationClick += (sender, e) => { Finish(); };

            //状态栏透明和间距处理
            StatusBarUtil.immersive(this);
            StatusBarUtil.setPaddingSmart(this, mToolbar);

            parallax = FindViewById(Resource.Id.parallax);
            var buttonBar     = FindViewById(Resource.Id.buttonBarLayout);
            var scrollView    = FindViewById <NestedScrollView>(Resource.Id.scrollView);
            var refreshLayout = FindViewById(Resource.Id.refreshLayout) as IRefreshLayout;

            refreshLayout.SetOnMultiPurposeListener(new CustomSimpleMultiPurposeListener(this));

            int lastScrollY = 0;
            int h           = DensityUtil.Dp2px(170);
            int color       = ContextCompat.GetColor(ApplicationContext, Resource.Color.colorPrimary) & 0x00ffffff;

            scrollView.ScrollChange += (sender, e) => {
                var scrollX = e.ScrollX;
                var scrollY = e.ScrollY;
                if (lastScrollY < h)
                {
                    scrollY         = Math.Min(h, scrollY);
                    mScrollY        = scrollY > h ? h : scrollY;
                    buttonBar.Alpha = 1f * mScrollY / h;
                    mToolbar.SetBackgroundColor(new Android.Graphics.Color(((255 * mScrollY / h) << 24) | color));
                    parallax.TranslationY = mOffset - mScrollY;
                }
                lastScrollY = scrollY;
            };

            buttonBar.Alpha = 0;
            mToolbar.SetBackgroundColor(new Android.Graphics.Color(0));
        }
Example #3
0
 public int Dp2Px(int value)
 {
     return(DensityUtil.Dp2px(Android.App.Application.Context, value));
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_fly_refresh);

            toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            toolbar.NavigationClick += (sender, e) => { Finish(); };

            /************************************************************
            * 关键代码-开始
            ************************************************************/

            mFlyView          = FindViewById <FlyView>(Resource.Id.flyview);
            mScenceView       = FindViewById <MountanScenceView>(Resource.Id.mountan);
            mFlyRefreshHeader = FindViewById <FlyRefreshHeader>(Resource.Id.flyrefresh);
            mFlyRefreshHeader.SetUp(mScenceView, mFlyView);                      //绑定场景和纸飞机
            mRefreshLayout = FindViewById(Resource.Id.refreshLayout) as IRefreshLayout;
            mRefreshLayout.SetReboundInterpolator(new ElasticOutInterpolator()); //设置回弹插值器,会带有弹簧震动效果
            mRefreshLayout.SetReboundDuration(800);                              //设置回弹动画时长
            mRefreshLayout.SetOnRefreshListener(new CustomOnRefreshListener(this));

            //设置 让 AppBarLayout 和 RefreshLayout 的滚动同步 并不保持 toolbar 位置不变
            appBar = FindViewById <AppBarLayout>(Resource.Id.app_bar);
            mRefreshLayout.SetOnMultiPurposeListener(new CustomOnMultiPurposeListener(this));

            /************************************************************
            * 关键代码-结束
            ************************************************************/

            mRefreshLayout = FindViewById(Resource.Id.refreshLayout) as IRefreshLayout;
            if (isFirstEnter)
            {
                isFirstEnter = false;
                mRefreshLayout.AutoRefresh();//第一次进入触发自动刷新,演示效果
            }

            /**
             * 初始化列表数据
             */
            initDataSet();
            mAdapter       = new ItemAdapter(this);
            mLayoutManager = new LinearLayoutManager(this);
            mListView      = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            mListView.SetLayoutManager(mLayoutManager);
            mListView.SetAdapter(mAdapter);
            mListView.SetItemAnimator(new SampleItemAnimator());
            mToolbarLayout = FindViewById <CollapsingToolbarLayout>(Resource.Id.toolbar_layout);
            mActionButton  = FindViewById <FloatingActionButton>(Resource.Id.fab);
            //设置点击 ActionButton 时候触发自动刷新 并改变主题颜色
            mActionButton.Click += (sender, e) => {
                updateTheme();
                mRefreshLayout.AutoRefresh();
            };

            // 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
            appBar.OffsetChanged += (sender, e) => {
                var   appBarLayout   = e.AppBarLayout;
                var   verticalOffset = e.VerticalOffset;
                int   scrollRange    = appBarLayout.TotalScrollRange;
                float fraction       = 1f * (scrollRange + verticalOffset) / scrollRange;
                if (fraction < 0.1 && misAppbarExpand)
                {
                    misAppbarExpand = false;
                    mActionButton.Animate().ScaleX(0).ScaleY(0);
                    mFlyView.Animate().ScaleX(0).ScaleY(0);
                    ValueAnimator animator = ValueAnimator.OfInt(mListView.PaddingTop, 0);
                    animator.SetDuration(300);
                    animator.Update += (senderr, ee) => {
                        mListView.SetPadding(0, (int)ee.Animation.AnimatedValue, 0, 0);
                    };
                    animator.Start();
                }
                if (fraction > 0.8 && !misAppbarExpand)
                {
                    misAppbarExpand = true;
                    mActionButton.Animate().ScaleX(1).ScaleY(1);
                    mFlyView.Animate().ScaleX(1).ScaleY(1);
                    ValueAnimator animator = ValueAnimator.OfInt(mListView.PaddingTop, DensityUtil.Dp2px(25));
                    animator.SetDuration(300);
                    animator.Update += (senderr, ee) => {
                        mListView.SetPadding(0, (int)ee.Animation.AnimatedValue, 0, 0);
                    };
                    animator.Start();
                }
            };

            //状态栏透明和间距处理
            StatusBarUtil.immersive(this);
            StatusBarUtil.setPaddingSmart(this, toolbar);
            //        StatusBarUtil.setPaddingSmart(this, findViewById(R.id.profile));
            //        StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurview));
        }