【问题标题】:How to create a tint filter on my app?如何在我的应用程序上创建色调过滤器?
【发布时间】:2017-03-03 04:30:45
【问题描述】:

我一直在到处寻找,但找不到答案。

我想知道如何在我的安卓应用程序的屏幕上进行着色,所以当我向上滑动时,它就像你在向上滑动一层一样。

例如,我打开应用程序,应用程序的主屏幕上有一个透明的灰色屏幕,我可以向上滑动它。

我知道这是可怕的解释所以问,我会尝试更具描述性。我正在为 Android 应用程序使用 Visual Studio 和 xamarin 和 c#。非常感谢 :)。任何建议都有帮助

【问题讨论】:

    标签: c# android visual-studio xamarin xamarin.android


    【解决方案1】:

    在您的页面上使用绝对布局。将其添加到所有子半透明框的顶部,背景颜色覆盖整个屏幕。实施手势识别器以检测向上挥动。检测到时,将您的盒子动画出屏幕。如果您使用表单,则手势识别器将位于该框的自定义渲染器中 对于表格:

    public class MyGestureListener : GestureDetector.SimpleOnGestureListener
    {
        OverlayBox box;
    
        public void SetBox(OverlayBox box)
        {
            this.box = box;
        }
        public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
        {
            Console.WriteLine($"OnFling velocityX={velocityX} velocityY={velocityY}");
            if (e2.RawY < e1.RawY) //add more constraints on X
            {
                Rectangle r = box.Bounds;
                r.Top = - r.Height;
                box.LayoutTo(r, 500);
            }
            //for fun
            Task.Delay(1000).ContinueWith(_ =>
            {
                    Rectangle r1 = box.Bounds;
                    r1.Top = 0;
                    box.LayoutTo(r1, 500);
            }); 
            return base.OnFling(e1, e2, velocityX, velocityY);
        }
    }
    
    
    class OverlayBoxRenderer : ViewRenderer<OverlayBox, Android.Views.View>
    {
        private readonly GestureDetector _detector;
        private readonly MyGestureListener _listener;
        public OverlayBoxRenderer()
        {
            _listener = new MyGestureListener();
            _detector = new GestureDetector(_listener);
        }
    
        protected override void OnElementChanged(ElementChangedEventArgs<OverlayBox> e)
        {
            if (e.NewElement == null)
            {
                this.Touch -= HandleTouch;
            }
    
            if (e.OldElement == null)
            {
                _listener.SetBox(e.NewElement);
                this.Touch += HandleTouch;
            }
    
    
        }
    
        void HandleTouch(object sender, TouchEventArgs e)
        {
            _detector.OnTouchEvent(e.Event);
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-07
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2013-07-30
      相关资源
      最近更新 更多