wxr
2020-06-16 f6fd8acd7c53c44187e70b4709443318a628f4b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
using System;
using Android.Views;
using Android.Content;
using Android.Widget;
using Android.Graphics.Drawables;
 
 
namespace Shared
{
 
    /// <summary>
    /// 首页轮播图
    /// </summary>
    public class HorizontalPages : ViewGroup
    {
 
        /// <summary>
        /// 视图高度
        /// </summary>
        /// <value>The height.</value>
        public override int Height
        {
            get
            {
                return base.Height;
            }
            set
            {
                base.Height = value;
                if (!IsCanRefresh)
                {
                    return;
                }
                var layoutParameters = realViewGroup.LayoutParameters;
                layoutParameters.Height = Height;
                realViewGroup.LayoutParameters = layoutParameters;
            }
        }
 
        /// <summary>
        /// 视图宽度
        /// </summary>
        /// <value>The width.</value>
        public override int Width
        {
            get
            {
                return base.Width;
            }
            set
            {
                base.Width = value;
                if (!IsCanRefresh)
                {
                    return;
                }
                var layoutParameters = realViewGroup.LayoutParameters;
                layoutParameters.Width = Width;
                realViewGroup.LayoutParameters = layoutParameters;
 
            }
        }
        //InnerHorizontalPages (realViewGroup as InnerHorizontalPages);
        /// <summary>
        /// 页面变化事件
        /// </summary>
        public Action<HorizontalPages, int> PageChange;
        /// <summary>
        /// 开始滑动事件
        /// </summary>
        public Action StartScrollAction;
        /// <summary>
        /// 结束滑动事件
        /// </summary>
        public Action EndScrollAction;
 
        ///// <summary>
        ///// 没有更多提示Action,已经是最后一个
        ///// </summary>
        //public Action NoMoreAction;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public HorizontalPages()
        {
            viewGroup = new AndroidFrameLayout(Application.Activity, null);
            realViewGroup = new InnerHorizontalPages(Application.Activity, this) { };
            //realViewGroup = InnerHorizontalPages;
            viewGroup.AddView(realViewGroup);
        }
 
        ImageView LeftImageView;
        ImageView RightImageView;
        /// <summary>
        /// 是否设置了虚假背景View 设置了才显示
        /// </summary>
        public bool IsSetLeftAndRightImageView = false;
        /// <summary>
        ///  设置控制最左和最右2边,填充的假背景View,不设置不显示,需要在AddChidren 前调用该方法
        /// </summary>
        /// <param name="mLeftImageView"></param>
        /// <param name="mRightImageView"></param>
        public void SetLeftAndRightImageView(ImageView mLeftImageView, ImageView mRightImageView)
        {
            if (mLeftImageView == null) return;
 
            if (mRightImageView == null) return;
 
            //设置之前先清空一次
            (realViewGroup as InnerHorizontalPages).RemoveAllViews();
 
            LeftImageView = mLeftImageView;
            (realViewGroup as InnerHorizontalPages).AddView(LeftImageView.AndroidView);
            LeftImageView.Parent = this;
            LeftImageView.Refresh();
 
            RightImageView = mRightImageView;
            (realViewGroup as InnerHorizontalPages).AddView(RightImageView.AndroidView);
            RightImageView.Parent = this;
            RightImageView.Refresh();
 
            IsSetLeftAndRightImageView = true;
 
        }
 
        int pageIndex;
        /// <summary>
        /// 设置或者获取当前的界面索引
        /// </summary>
        /// <value>The index of the page.</value>
        public int PageIndex
        {
            get
            {
                return (realViewGroup as InnerHorizontalPages).CurrentScreen;
            }
            set
            {
                if (value < 0 || ChildrenCount < value)
                {
                    return;
                }
                pageIndex = value;
                if (!IsCanRefresh)
                {
                    return;
                }
 
                (realViewGroup as InnerHorizontalPages).SetSelection(value);
            }
        }
 
        /// <summary>
        /// 是否允许滑动
        /// </summary>
        /// <value><c>true</c> if scroll enabled; otherwise, <c>false</c>.</value>
        public bool ScrollEnabled
        {
            get
            {
                return (realViewGroup as InnerHorizontalPages).ScrollEnabled;
            }
            set
            {
                (realViewGroup as InnerHorizontalPages).ScrollEnabled = value;
            }
        }
 
 
 
        /// <summary>
        /// 增加子控件
        /// </summary>
        /// <param name="view">View.</param>
        public override void AddChidren(View view)
        {
            view.Parent = this;
            viewList.Add(view);
            (realViewGroup as InnerHorizontalPages).AddView(view.AndroidView);
 
            if (!IsCanRefresh)
            {
                return;
            }
 
            view.Refresh();
 
            if (view is ViewGroup)
            {
                var tempViewGroup = (ViewGroup)view;
                for (int i = 0; i < tempViewGroup.ChildrenCount; i++)
                {
                    tempViewGroup.GetChildren(i).Refresh();
                }
            }
        }
 
        /// <summary>
        /// 移除当前控件
        /// </summary>
        /// <param name="view">View.</param>
        internal override void Remove(View view)
        {
            //if (view == null)
            //{
            //    return;
            //}
            //var index = viewList.FindIndex(obj => obj == view);
            //if (index < 0)
            //{
            //    return;
            //}
 
            //viewList.Remove(view);
            //(realViewGroup as InnerHorizontalPages).RemoveViewAt(index);
            //view.Parent = null;
 
         
 
 
            base.Remove(view);
            (realViewGroup as InnerHorizontalPages).ReLocation();
 
            if (PageIndex > ChildrenCount - 1)
            {
                PageIndex = ChildrenCount - 1;
            }
        }
 
        /// <summary>
        /// 移除所有的控件
        /// </summary>
        public override void RemoveAll()
        {
            //while (0 < viewList.Count)
            //{
            //    GetChildren(0)?.RemoveFromParent();
            //}
            //(realViewGroup as InnerHorizontalPages).SetSelection(0);
 
            base.RemoveAll();
            (realViewGroup as InnerHorizontalPages).ReLocation();
            PageIndex = 0;
        }
 
        /// <summary>
        /// 根据索引移除控件
        /// </summary>
        /// <param name="index">Index.</param>
        public override void RemoveAt(int index)
        {
            if (viewList.Count - 1 < index || index < 0)
            {
                return;
            }
            Remove(viewList[index]);
        }
 
 
        /// <summary>
        /// 界面之间的边距
        /// </summary>
        public int JMBJ
        {
            get
            {
                return (realViewGroup as InnerHorizontalPages).JMBJ;
            }
            set
            {
                (realViewGroup as InnerHorizontalPages).JMBJ = value;
                (realViewGroup as InnerHorizontalPages).RefreshPageWidth();
 
            }
        }
 
        /// <summary>
        /// 突出宽度
        /// </summary>
        public int TCBJ
        {
            get
            {
                return (realViewGroup as InnerHorizontalPages).TCBJ;
            }
            set
            {
                (realViewGroup as InnerHorizontalPages).TCBJ = value;
                (realViewGroup as InnerHorizontalPages).RefreshPageWidth();
            }
        }
 
    
 
 
 
        //********************Transform3D 旋转效果方法**********************
        ////默认20度
        //float transformAngle = 20;
        ////旋转角度
        //public int TransformAngle
        //{
        //    set
        //    {
        //        transformAngle = value;
        //    }
        //}
 
        //
        //public void RefreshPageView()
        //{
 
        //    //RefreshViewWithTransform3D();
        //    //RefreshViewWithChangeHeight();
        //    (realViewGroup as InnerHorizontalPages).RefreshViewWithChangeHeight();
        //}
 
 
        //public void RefreshViewWithTransform3D()
        //{
        //    if (viewList.Count <= 0) return;
 
        //    if (PageIndex > viewList.Count - 1)
        //    {
        //        PageIndex = viewList.Count - 1;
        //    }
 
        //    viewList[PageIndex].AndroidView.RotationY = 0;
 
        //    //判断PageIndex 前后是否有view,并旋转
        //    if (PageIndex - 1 >= 0)
        //    {
        //        viewList[PageIndex - 1].AndroidView.RotationY = transformAngle;
        //    }
 
        //    if (PageIndex <= viewList.Count - 2)
        //    {
        //        viewList[PageIndex + 1].AndroidView.RotationY = -1 * transformAngle;
        //    }
 
        //}
 
 
        public bool isScrolling;
        /// <summary>
        /// 是否正在滑动
        /// </summary>
        public bool ISScrolling
        {
            get
            {
                return isScrolling;
            }
        }
 
        /// <summary>
        /// 是否正在滑动
        /// </summary>
        /// <value><c>true</c> if decelerating; otherwise, <c>false</c>.</value>
        public bool Decelerating
        {
            get
            {
                return isScrolling;
            }
        }
 
 
    }
 
    public class InnerHorizontalPages : Android.Widget.FrameLayout
    {
        public bool ScrollEnabled = true;
        static int snapVelocity = 1000;
        static int invalidScreen = -1;
        static int touchStateRest = 0;
        static int touchStateScrolling = 1;
 
        /// <summary>
        /// 界面之间的边距
        /// </summary>
        public int JMBJ = 0;
        //突出宽度
        public int TCBJ = 100;
        Scroller scroller;
        VelocityTracker mVelocityTracker = VelocityTracker.Obtain();
        int touchState = touchStateRest;
        float lastMotionX;
        float lastMotionY;
        int mTouchSlop;
        int mMaximumVelocity;
        internal int CurrentScreen;
 
 
        int mPageWidth;
 
        public void RefreshPageWidth()
        {
            mPageWidth = (int)LayoutParameters.Width - 2 * (TCBJ + JMBJ);
        }
 
 
        //public override void RemoveViewAt(int index)
        //{
        //    int nowScreen = CurrentScreen;
        //    if (index == horizontalPages.ChildrenCount - 1)
        //    {
        //        nowScreen--;
        //        if (nowScreen < 0)
        //        {
        //            nowScreen = 0;
        //        }
        //    }
        //    base.RemoveViewAt(index);
        //    ReLocation();
        //    snapToScreen(nowScreen, true);
        //    //刷新
        //    //snapToDestination();
        //}
 
        Shared.HorizontalPages horizontalPages;
        public InnerHorizontalPages(Context context, Shared.HorizontalPages view) : base(context)
        {
            horizontalPages = view;
            init();
        }
 
 
 
        /// <summary>
        /// 重写这个是为了方便部局,在每个界面之间都多加了一个控件包住
        /// </summary>
        /// <param name="child"></param>
        public override void AddView(Android.Views.View child)
        {
            base.AddView(child);
            ReLocation();
        }
 
        /// <summary>
        /// 重新排位置及设备内容大小
        /// </summary>
        public virtual void ReLocation()
        {
            try
            {
                if (horizontalPages.ChildrenCount == 0)
                {
                    return;
                }
 
                horizontalPages.GetChildren(0).AndroidView.SetX(TCBJ + JMBJ);
 
                for (int i = 1; i < horizontalPages.ChildrenCount; i++)
                {
                    horizontalPages.GetChildren(i).AndroidView.SetX((int)horizontalPages.GetChildren(i - 1).AndroidView.GetX() + horizontalPages.GetChildren(i - 1).AndroidView.LayoutParameters.Width + JMBJ);
                }
 
                if (horizontalPages.IsSetLeftAndRightImageView)
                {
                    var mHeight = LayoutParameters.Height - JMBJ * 2;
                    //System.Console.WriteLine("ChildCountl:"+ChildCount.ToString() + "  ChildrenCount:" + horizontalPages.ChildrenCount);
 
                    var layoutParameters = GetChildAt(0).LayoutParameters;
                    layoutParameters.Width = mPageWidth;
                    layoutParameters.Height = mHeight;
                    GetChildAt(0).LayoutParameters = layoutParameters;
                    GetChildAt(0).SetX(TCBJ - mPageWidth);
                    GetChildAt(0).SetY(JMBJ);
 
 
                    var layoutParameters2 = GetChildAt(1).LayoutParameters;
                    layoutParameters2.Width = mPageWidth;
                    layoutParameters2.Height = mHeight;
                    GetChildAt(1).LayoutParameters = layoutParameters2;
                    GetChildAt(1).SetY(JMBJ);
                    GetChildAt(1).SetX((int)horizontalPages.GetChildren(horizontalPages.ChildrenCount - 1).AndroidView.GetX() + mPageWidth + JMBJ);
 
                }
 
                RefreshPageView();
            }
            catch { }
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        bool CheckIfStartOrEnd()
        {
            return (deltaX > 0 && CurrentScreen == horizontalPages.ChildrenCount - 1) || (deltaX < 0 && CurrentScreen == 0);
        }
 
 
        /// <summary>
        /// 判断是否需要发送结束滑动事件
        /// </summary>
        void SendEndScrollAction()
        {
            if (isStart)
            {
                isStart = false;
                horizontalPages.EndScrollAction?.Invoke();
            }
        }
 
 
 
        //bool isNoMore;
        bool isStart;
        int moveX;
        void init()
        {
            scroller = new Scroller(Context);
            var configuration = ViewConfiguration.Get(Context);
            //最小的滑动距离
            mTouchSlop = configuration.ScaledTouchSlop;
            mMaximumVelocity = configuration.ScaledMaximumFlingVelocity;
 
            ScrollChange += (s, e) =>
            {
                moveX = ScrollX - beforeXScrollX;
                RefreshPageView();
 
                //Shared.HDLUtils.WriteLine($"HorizontalPages Scrolled ScrollX:{ScrollX}  WIDTH:{Width}");
                if (mTouchSlop < Math.Abs(moveX))
                {
                    if (!isStart)
                    {
                        //当前索引为,不是第一个或者最后一个,滑动距离大于触发距离并且没执行过则 执行一次StartScrollAction
                        if ((moveX > 0 && CurrentScreen < horizontalPages.ChildrenCount - 1) || (moveX < 0 && CurrentScreen > 0))
                        {
                            isStart = true;
                            horizontalPages.StartScrollAction?.Invoke();
                        }
 
                    }
                }
 
            };
 
        }
 
        /// <summary>
        /// 自动计算刷新所有View的高度,实现缩放效果
        /// </summary>
        public void RefreshPageView()
        {
            //RefreshViewWithTransform3D();
            RefreshViewWithChangeHeight();
        }
 
 
 
        /// <summary>
        /// 刷新最大距离值
        /// </summary>
        double MaxDistance;
        //public void RefreshMaxDistance()
        //{
        //    MaxDistance = Width - 2 * TCBJ - JMBJ;
        //}
 
        /// <summary>
        /// 计算滑动缩放高度的方法
        /// </summary>
        public void RefreshViewWithChangeHeight()
        {
            if (horizontalPages.ChildrenCount <= 0) return;
 
            MaxDistance = LayoutParameters.Width - 2 * TCBJ - JMBJ;
 
            //方法1
            for (int i = 0; i < horizontalPages.viewList.Count; i++)
            {
                double distance = Math.Abs(horizontalPages.viewList[i].X - ScrollX - TCBJ - JMBJ);
                var HH = 0;
                if (distance <= 0)
                {
                    HH = 0;
                }
                else if (distance >= MaxDistance)
                {
                    HH = JMBJ;
                }
                else
                {
                    HH = (int)((distance / MaxDistance) * JMBJ);
                }
 
                horizontalPages.viewList[i].Height = LayoutParameters.Height - HH * 2;
                horizontalPages.viewList[i].Y = HH;
 
                RefreshSubviewHeight(horizontalPages.viewList[i], horizontalPages.viewList[i].Height);
            }
        }
 
        /// <summary>
        /// 同时刷新子view 和ImageView的高度,暂时解决底部圆角失效问题
        /// </summary>
        /// <param name="mView"></param>
        /// <param name="height"></param>
        void RefreshSubviewHeight(View mView, float height)
        {
            try
            {
                if (mView is ViewGroup)
                {
                    var tempViewGroup = (ViewGroup)mView;
                    for (int i = 0; i < tempViewGroup.ChildrenCount; i++)
                    {
                        if (tempViewGroup.GetChildren(i) is ViewGroup)
                        {
                            var tempViewGroup2 = (ViewGroup)tempViewGroup.GetChildren(i);
                            for (int j = 0; j < tempViewGroup2.ChildrenCount; j++)
                            {
                                if (tempViewGroup2.GetChildren(j) is ImageView && tempViewGroup2.GetChildren(j).Tag.ToString() == "R")
                                {
 
                                    tempViewGroup2.GetChildren(j).Height = (int)height;
                                    break;
                                }
                            }
                            if (tempViewGroup2.Tag.ToString() == "R")
                            {
                                tempViewGroup2.Height = (int)height;
                                break;
                            }
                        }
 
                    }
                }
            }
            catch { }
        }
 
 
        public override void RequestDisallowInterceptTouchEvent(bool disallowIntercept)
        {
            base.RequestDisallowInterceptTouchEvent(disallowIntercept);
            disallowInterceptTouchEvent = disallowIntercept;
        }
        bool disallowInterceptTouchEvent;
 
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            if (disallowInterceptTouchEvent)
            {
                return false;
            }
            //Shared.HDLUtils.WriteLine($"HorizontalPages->OnInterceptTouchEvent:{Height}   {ev.Action}");
            //如果没有子控件或者不允许滑动就返回,不处理当前事件
            if (horizontalPages.ChildrenCount == 0 || !ScrollEnabled)
                return false;
 
            mVelocityTracker.AddMovement(ev);
            var x = ev.GetX();
            var y = ev.GetY();
            switch (ev.Action)
            {
                //每次点击都执行这里
                case MotionEventActions.Down:
 
                    beforeXScrollX = ScrollX;
                    if (!scroller.IsFinished)
                    {
                        //如果还在滑动,但是用户重新点击了,就让控件马上停止
                        scroller.AbortAnimation();
                    }
                    //记录点击的最新X坐标
                    lastMotionX = x;
                    lastMotionY = y;
                    touchState = scroller.IsFinished ? touchStateRest : touchStateScrolling;
 
                    //IfAction = true;
                    //isNoMore = false;
                    //isStart = false;
                    ////开始滑动事件
                    //horizontalPages.StartScrollAction?.Invoke() ;
                    break;
                //有子控件时执行这里
                case MotionEventActions.Move:
                    var deltaX = (int)(lastMotionX - x);
                    var deltaY = (int)(lastMotionY - y);
                    //当前滑动是否已经超出了设定值
                    var xMoved = Math.Abs(deltaX) > mTouchSlop;
                    if (xMoved && Math.Abs(deltaY) < Math.Abs(deltaX))
                    {
                        touchState = touchStateScrolling;
                        //isNoMore = false;
                    }
                    if (touchState == touchStateScrolling)
                    {
                        //记录最新的坐标,因为接下来控件已经滑动了
                        lastMotionX = x;
                        //当前事件自己处理了,子控制不需要处理当前这事件
                        return true;
                    }
                    break;
                case MotionEventActions.Cancel:
                    touchState = touchStateRest;
                    mVelocityTracker.Clear();
 
                    break;
            }
            return false;
        }
        int deltaX;
        int beforeXScrollX;
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (disallowInterceptTouchEvent)
            {
                return false;
            }
 
            if (horizontalPages.ChildrenCount == 0 || !ScrollEnabled)
                return false;
 
            mVelocityTracker.AddMovement(e);
 
            var x = e.GetX();
            var y = e.GetY();
            switch (e.Action)
            {
                case MotionEventActions.Move:
                    SetIsScrolling(true);
                    deltaX = (int)(lastMotionX - x);
                    var deltaY = (int)(lastMotionY - y);
                    //当前滑动是否已经超出了设定值
                    var xMoved = Math.Abs(deltaX) > mTouchSlop;
                    if (xMoved && Math.Abs(deltaY) < Math.Abs(deltaX))
                    {
                        touchState = touchStateScrolling;
                    }
 
                    if (touchState == touchStateScrolling)
                    {
                        lastMotionX = x;
                        int scrollX = ScrollX;
                        //向右滑动
                        if (deltaX < 0)
                        {
                            //之前已经滑动的X轴
                            if (scrollX > 0)
                            {
                                //向右滑动时显示出左边的界面,最低的长度为之前已经滑动的距离
                                ScrollBy(Math.Max(-scrollX, deltaX), 0);
                            }
                        }
                        //向左滑动
                        else if (deltaX > 0)
                        {
                            //最小的右边需要滑动的距离
                            int availableToScroll = (int)horizontalPages.GetChildren(
                                   horizontalPages.ChildrenCount - 1).AndroidView.GetX() + horizontalPages.GetChildren(
                                   horizontalPages.ChildrenCount - 1).AndroidView.LayoutParameters.Width + TCBJ + JMBJ
                                   - PaddingRight - HorizontalFadingEdgeLength
                                   - scrollX - Width;
                            if (availableToScroll > 0)
                            {
                                ScrollBy(Math.Min(availableToScroll, deltaX), 0);
                            }
                        }
                        return true;
                    }
                    break;
 
                case MotionEventActions.Up:
                case MotionEventActions.Cancel:
                    //IfAction = true;
                    if (touchState == touchStateScrolling)
                    {
                        mVelocityTracker.ComputeCurrentVelocity(1000, mMaximumVelocity);
                        var velocityX = mVelocityTracker.XVelocity;
                        var moveX = ScrollX - beforeXScrollX;
                        if (mTouchSlop < Math.Abs(moveX) || velocityX > snapVelocity)
                        {
                            if (moveX < 0)
                            {
                                // 显示左边界面
                                snapToScreen(CurrentScreen - 1);
                            }
                            else if (moveX > 0)
                            {
                                // 显示右边界面
                                snapToScreen(CurrentScreen + 1);
                            }
                        }
                        else
                        {
                            snapToScreen(CurrentScreen);
                        }
                    }
                    else
                    {
                        snapToScreen(CurrentScreen);
                    }
 
                    //if (Math.Abs(deltaX) > mTouchSlop)
                    //{
                    //    if (!isNoMore && !bSendPageChange)
                    //    {
                    //        //当前索引为第一个或者最后一个,滑动距离大于触发距离、没执行过、PageIndex没变化、则执行一次NoMoreAction
                    //        if ((deltaX > 0 && CurrentScreen == horizontalPages.ChildrenCount - 1 && ScrollX >= Width) || (deltaX < 0 && CurrentScreen == 0 && ScrollX <= 0))
                    //        {
                    //            isNoMore = true;
                    //            horizontalPages.NoMoreAction?.Invoke();
                    //        }
 
                    //    }
                    //}
 
                    touchState = touchStateRest;
                    mVelocityTracker.Clear();
                    break;
 
            }
            return true;
        }
 
        /// <summary>
        /// 滑动到指定的界面
        /// </summary>
        public void snapToDestination(bool isDelay = true)
        {
            var whichScreen = (ScrollX + (MeasuredWidth / 2)) / MeasuredWidth;
 
            snapToScreen(whichScreen, isDelay);
        }
        /// <summary>
        /// 滑动到指定界面
        /// </summary>
        /// <param name="whichScreen">Which screen.</param>
        void snapToScreen(int whichScreen, bool isDelay = true)
        {
            if (!scroller.IsFinished)
            {
                scroller.AbortAnimation();
            }
            var beforePosition = CurrentScreen;
            whichScreen = Math.Max(0, Math.Min(whichScreen, horizontalPages.ChildrenCount - 1));
            CurrentScreen = whichScreen;
            //还原这个控件之前的位置
            int newX = 0;
            if (CurrentScreen != 0)
            {
                newX = (int)horizontalPages.GetChildren(CurrentScreen).AndroidView.GetX() - TCBJ - JMBJ;
            }
 
            SetIsScrolling(true);
            var delta = newX - ScrollX;
            scroller.StartScroll(ScrollX, 0, delta, 0, isDelay ? 400 : 0);
            Invalidate();
            SendIfPageChange(isDelay ? 400 : 0);
 
            //Shared.HDLUtils.WriteLine("HorizontalPages StartScroll");
            if (beforePosition != CurrentScreen)
            {
                RefreshPageView();
                bSendPageChange = true;
                //DelayPageChange();
                //horizontalPages.PageChange?.Invoke(horizontalPages, CurrentScreen);
 
            }
        }
 
        private void SetIsScrolling(bool bSctolling)
        {
            if (horizontalPages.isScrolling == bSctolling) return;
 
            //Shared.HDLUtils.WriteLine($"HorizontalPages StartScroll: {bSctolling}");
            horizontalPages.isScrolling = bSctolling;
        }
 
        System.Threading.Thread sendThread;
        //string SendmarkStr;
        bool bSendPageChange = false;
        /// <summary>
        /// 判断是否要发送改变事件
        /// </summary>
        private void SendIfPageChange(int DELAY = 400)
        {
            try
            {
                if (sendThread != null)
                    sendThread.Abort();
 
                sendThread = new System.Threading.Thread(async () =>
                {
                    System.Threading.Thread.Sleep(DELAY + 100);
                    Application.RunOnMainThread(() =>
                    {
 
                        SetIsScrolling(false);
                        if (bSendPageChange)
                        {
                            bSendPageChange = false;
                            horizontalPages.PageChange?.Invoke(horizontalPages, CurrentScreen);
                        }
 
                        SendEndScrollAction();
                        HDLUtils.WriteLine($"HorizontalPages SendIfPageChange______________-----------");
                    });
                })
                { IsBackground = true };
 
                sendThread.Start();
            }
            catch
            {
 
            }
 
        }
 
        //public void DelayPageChange()
        //{
        //    new System.Threading.Thread(async () =>
        //    {
        //        System.Threading.Thread.Sleep(500);
        //        Application.RunOnMainThread(() =>
        //        {
        //            horizontalPages.PageChange?.Invoke(horizontalPages, CurrentScreen);
        //        });
        //    })
        //    { IsBackground = true }.Start();
        //}
 
        public override void ComputeScroll()
        {
            if (scroller.ComputeScrollOffset())
            {
                ScrollTo(scroller.CurrX, scroller.CurrY);
                PostInvalidate();
            }
            else if (CurrentScreen != invalidScreen)
            {
                //mCurrentScreen = Math.Max(0, Math.Min(mNextScreen, horizontalPages.ChildrenCount - 1));
                //mNextScreen = invalidScreen;
                //postViewSwitched(mLastScrollDirection);
            }
        }
 
        public void SetSelection(int position)
        {
            if (position < 0)
            {
                return;
            }
 
            scroller.ForceFinished(true);
 
            position = Math.Min(position, horizontalPages.ChildrenCount - 1);
 
            if(position != CurrentScreen)
            {
                isStart = true;
                horizontalPages.StartScrollAction?.Invoke();
            }
 
            snapToScreen(position, false);
        }
 
        public override bool DispatchTouchEvent(MotionEvent e)
        {
            //Shared.HDLUtils.WriteLine($"PageLayout->DispatchTouchEvent:{Height}   {e.Action}");
            if (e.Action == MotionEventActions.Down)
            {
                //还原中断
                RequestDisallowInterceptTouchEvent(false);
 
                Parent.RequestDisallowInterceptTouchEvent(true);
            }
            else if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Cancel)
            {
                Parent.RequestDisallowInterceptTouchEvent(false);
            }
            return base.DispatchTouchEvent(e);
        }
    }
}