Exemplo n.º 1
0
        public AbsoluteLayout()
        {
            InitializeComponent();

            var layout = new Xamarin.Forms.AbsoluteLayout();

            var aquaBox = new BoxView {
                Color = Color.Aqua
            };

            layout.Children.Add(aquaBox,
                                new Rectangle(0, 0, 1, 1),
                                AbsoluteLayoutFlags.All);

            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(aquaBox, new Rectangle(0, 0, 1, 1));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(aquaBox, AbsoluteLayoutFlags.HeightProportional);

            Content = layout;
        }
Exemplo n.º 2
0
        public AbsoluteLayoutCodeBehind()
        {
            InitializeComponent();
            var layout = new Xamarin.Forms.AbsoluteLayout();

            Content = layout;
            var AquaBoxView = new BoxView {
                BackgroundColor = Color.Aqua
            };

            layout.Children.Add(AquaBoxView, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All);
            var whiteboxview = new BoxView {
                BackgroundColor = Color.White
            };

            layout.Children.Add(whiteboxview, new Rectangle(0.5, 0.1, 100, 100), AbsoluteLayoutFlags.PositionProportional);
            var botao = new Button {
                Text = "Texto do Botão"
            };

            layout.Children.Add(botao, new Rectangle(0, 1, 1, 0.1), AbsoluteLayoutFlags.All);
        }
Exemplo n.º 3
0
        public PuzzlePage()
        {
            // AbsoluteLayout to host the squares.
            absoluteLayout = new Xamarin.Forms.AbsoluteLayout()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            };


            // Create XuzzleSquare's for all the rows and columns.


            Image[] normalImages = new Image[NUM * NUM];


            int index = 0;



            for (int row = 0; row < NUM; row++)
            {
                for (int col = 0; col < NUM; col++)
                {
                    // But skip the last one!
                    if (row == NUM - 1 && col == NUM - 1)
                    {
                        break;
                    }



                    // Instantiate the image reading it from the local resources.
                    normalImages[index] = new Image();

                    if (NUM == 2)
                    {
                        normalImages[index].Source = ImageSource
                                                     .FromResource(String.Format("Puzzles.Images.flower" + index + ".png"));
                    }
                    if (NUM == 4)
                    {
                        normalImages[index].Source = ImageSource
                                                     .FromResource(String.Format("Puzzles.ImagesMedium.insect" + index + ".png"));
                    }
                    if (NUM == 5)
                    {
                        normalImages[index].Source = ImageSource
                                                     .FromResource(String.Format("Puzzles.Images5X5.nature" + index + ".png"));
                    }



                    //Bitmap bmp = BitmapFactory.DecodeResourceAsync(String.Format("Puzzles.test.png"));
                    //BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
                    //bitmapDrawable.SetTileModeXY(Shader.TileMode.Repeat, Shader.TileMode.Repeat);



                    //getPuzzleBitmap(image);

                    //ImageView imageview = (ImageView)("Puzzles.test.png");

                    //Bitmap drawingCache = imageview.GetDrawingCache(true);
                    //Canvas canvas = new Canvas();
                    //Rect src = new Rect(23, 12, 23, 12);
                    //RectF dst = new RectF(0, 20, 0, 20); Paint paint = new Paint();
                    //canvas.DrawBitmap(drawingCache, src, dst, paint);



                    //Bitmap piece = Bitmap.CreateBitmap(normalImages, row, col, 30, 30);



                    //Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
                    //Bitmap myLogo = ((BitmapDrawable)myDrawable).getBitmap();



                    // Instantiate XuzzleSquare.
                    PuzzleSquare square = new PuzzleSquare(normalImages[index], index)
                    {
                        Row = row,
                        Col = col
                    };



                    // Add tap recognition
                    TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer
                    {
                        Command          = new Command(OnSquareTapped),
                        CommandParameter = square
                    };
                    square.GestureRecognizers.Add(tapGestureRecognizer);

                    //Bitmap bitmap = BitmapFactory.DecodeFile("Puzzles.test.png");
                    //cropBitmap(bitmap, Convert.ToInt32(square.WidthRequest), Convert.ToInt32(square.HeightRequest));
                    // Add it to the array and the AbsoluteLayout.
                    squares[row, col] = square;

                    absoluteLayout.Children.Add(square);
                    index++;
                }
            }


            // This is the "Randomize" button.
            randomizeButton = new Xamarin.Forms.Button
            {
                Text = "Randomize",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };
            randomizeButton.Clicked += OnRandomizeButtonClicked;

            // Label to display elapsed time.
            timeLabel = new Label
            {
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };


            // Put everything in a StackLayout.
            stackLayout = new StackLayout
            {
                Children =
                {
                    new StackLayout {
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          =
                        {
                            randomizeButton,
                            timeLabel,
                        }
                    },
                    absoluteLayout
                }
            };
            stackLayout.SizeChanged += OnStackSizeChanged;

            // And set that to the content of the page.
            this.Padding =
                new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
            this.Content = stackLayout;
        }
        public GestureTestPage()
        {
            #region Page

            //var pageListener = FormsGestures.Listener.For(this);

            //pageListener.LongPressing += (s, e) => System.Diagnostics.Debug.WriteLine("\tPAGE LONG PRESSING");
            //pageListener.LongPressed += (s, e) => System.Diagnostics.Debug.WriteLine("\tPAGE LONG PRESSED");


            #endregion

            #region Xamarin.Forms.Button
            var button = new Button
            {
                BackgroundColor = Color.Pink,
                Text            = "Hello",
                BorderColor     = Color.Blue,
                BorderWidth     = 3,
            };
            button.Clicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON CLICKED!!!!");


            var buttonListener = FormsGestures.Listener.For(button);

            buttonListener.Down         += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON DOWN [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]"); // does not work with UIControl derived elements
            buttonListener.RightClicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON RIGHT CLICK[" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");

            buttonListener.LongPressing += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON LONG PRESSING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            buttonListener.Panning      += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PANNING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
                button.TranslationX += e.DeltaDistance.X;
                button.TranslationY += e.DeltaDistance.Y;
            };
            buttonListener.Pinching += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PINCHING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
                button.Scale *= e.DeltaScale;
            };
            buttonListener.Rotating += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBUTTON ROTATING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
                button.Rotation += e.DeltaAngle;
            };

            buttonListener.Up           += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON UP [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");                               // does not work with UIControl derived elements
            buttonListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON TAPPED #[" + e.NumberOfTaps + "] [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]"); // does not work with UIControl derived elements
            buttonListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON DOUBLE TAPPED [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");                    // does not work with UIControl derived elements

            buttonListener.LongPressed += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON LONG PRESSED [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            buttonListener.Panned      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON PANNED TotalDistance=[" + e.TotalDistance + "][" + e.Center + "][" + e.ViewPosition + "]");
            buttonListener.Swiped      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON SWIPED!!! Velocity=[" + e.VelocityX + "," + e.VelocityY + "][" + e.Center + "][" + e.ViewPosition + "]");

            buttonListener.Pinched += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON PINCHED TotalScale=[" + e.TotalScale + "][" + e.Center + "][" + e.ViewPosition + "]");
            buttonListener.Rotated += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON ROTATED TotalAngle=[" + e.TotalAngle + "][" + e.Center + "][" + e.ViewPosition + "]");

            #endregion


            #region Forms9Patch.Frame
            var frame = new Forms9Patch.Frame
            {
                BackgroundColor = Color.Orange,
                WidthRequest    = 70,
                HeightRequest   = 70,
                HasShadow       = true,
                OutlineColor    = Color.Green,
                OutlineRadius   = 0,
                OutlineWidth    = 1,
                Content         = new Forms9Patch.Label {
                    Text = "pizza", TextColor = Color.White, BackgroundColor = Color.Blue, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start
                }
            };
            var frameListener = FormsGestures.Listener.For(frame);

            frameListener.Down += (sender, e) =>
            {
                e.Handled = true;
                System.Diagnostics.Debug.WriteLine("\tFRAME DOWN [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            };
            frameListener.LongPressing += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME LONG PRESSING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            frameListener.RightClicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME RIGHT CLICK[" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");

            frameListener.Panning += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME PANNING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
                frame.TranslationX += e.DeltaDistance.X;
                frame.TranslationY += e.DeltaDistance.Y;
            };

            frameListener.Pinching += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME PINCHING [" + e.Center + "][" + e.Touches[0] + "][" + e.DeltaScale + "][" + e.ViewPosition + "]");
                frame.Scale *= e.DeltaScale;
            };
            frameListener.Rotating += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tFRAME ROTATING [" + e.Center + "][" + e.Touches[0] + "][" + e.DeltaAngle + "][" + e.ViewPosition + "]");
                frame.Rotation += e.DeltaAngle;
            };

            frameListener.Up           += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME UP [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            frameListener.Tapping      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME TAPPING #[" + e.NumberOfTaps + "] [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            frameListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME TAPPED #[" + e.NumberOfTaps + "] [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            frameListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME DOUBLE TAPPED [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");

            frameListener.LongPressed += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME LONG PRESSED [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            frameListener.Panned      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME PANNED TotalDistance=[" + e.TotalDistance + "][" + e.Center + "][" + e.ViewPosition + "]");
            frameListener.Swiped      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME SWIPED!!! Velocity=" + e.VelocityX + "," + e.VelocityY + "][" + e.Center + "][" + e.ViewPosition + "]");

            frameListener.Pinched += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME PINCHED TotalScale=[" + e.TotalScale + "][" + e.Center + "][" + e.ViewPosition + "]");
            frameListener.Rotated += (sender, e) => System.Diagnostics.Debug.WriteLine("\tFRAME ROTATED TotalAngle[" + e.TotalAngle + "][" + e.Center + "][" + e.ViewPosition + "]");
            #endregion


            #region Xamarin.Forms.BoxView
            var box = new BoxView
            {
                BackgroundColor = Color.Green,
            };
            var boxListener = FormsGestures.Listener.For(box);

            //boxListener.Down += OnDown;
            boxListener.Down += (sender, e) =>
            {
                e.Handled = true;
                System.Diagnostics.Debug.WriteLine("\tBOX DOWN [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            };
            boxListener.LongPressing += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX LONG PRESSING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            boxListener.RightClicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX RIGHT CLICK[" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");

            boxListener.Panning += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX PANNING [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
                box.TranslationX += e.DeltaDistance.X;
                box.TranslationY += e.DeltaDistance.Y;
            };

            boxListener.Pinching += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX PINCHING [" + e.Center + "][" + e.Touches[0] + "][" + e.DeltaScale + "][" + e.ViewPosition + "]");
                box.Scale *= e.DeltaScale;
            };
            boxListener.Rotating += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("\tBOX ROTATING [" + e.Center + "][" + e.Touches[0] + "][" + e.DeltaAngle + "][" + e.ViewPosition + "]");
                box.Rotation += e.DeltaAngle;
            };

            boxListener.Up           += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX UP [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            boxListener.Tapping      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX TAPPING #[" + e.NumberOfTaps + "] [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            boxListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX TAPPED #[" + e.NumberOfTaps + "] [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            boxListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX DOUBLE TAPPED [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");

            boxListener.LongPressed += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX LONG PRESSED [" + e.Center + "][" + e.Touches[0] + "][" + e.ViewPosition + "]");
            boxListener.Panned      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX PANNED TotalDistance=[" + e.TotalDistance + "][" + e.Center + "][" + e.ViewPosition + "]");
            boxListener.Swiped      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX SWIPED!!! Velocity=" + e.VelocityX + "," + e.VelocityY + "][" + e.Center + "][" + e.ViewPosition + "]");

            boxListener.Pinched += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX PINCHED TotalScale=[" + e.TotalScale + "][" + e.Center + "][" + e.ViewPosition + "]");
            boxListener.Rotated += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX ROTATED TotalAngle[" + e.TotalAngle + "][" + e.Center + "][" + e.ViewPosition + "]");

            #endregion


            #region Looking for multiple taps
            var tapBox = new BoxView
            {
                BackgroundColor = Color.Blue,
            };
            var tapBoxListener = FormsGestures.Listener.For(tapBox);

            tapBoxListener.Tapping      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tTAPBOX TAPPING #[" + e.NumberOfTaps + "]");
            tapBoxListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tTAPBOX TAPPED #[" + e.NumberOfTaps + "]");
            tapBoxListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tTAPBOX DOUBLE TAPPED #[" + e.NumberOfTaps + "]");

            #endregion


            #region RelativeLayout
            relativeLayout = new Xamarin.Forms.RelativeLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(0),
                BackgroundColor   = Color.Transparent,
            };
            relativeLayout.Children.Clear();

            relativeLayout.Children.Add(button,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width * 3 / 4); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height * 3 / 4); }),
                                        widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 3); }),
                                        heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 3); })
                                        );
            relativeLayout.Children.Add(box,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width / 4); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 4); }),
                                        widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 2); }),
                                        heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 2); })
                                        );
            relativeLayout.Children.Add(tapBox,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width / 8); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 8); }),
                                        widthConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 16); }),
                                        heightConstraint: Constraint.RelativeToParent((parent) => { return(parent.Width / 16); })
                                        );
            relativeLayout.Children.Add(frame,
                                        xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width * 1 / 4); }),
                                        yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 8); })
                                        );

            #endregion


            #region AbsoluteLayout
            absoluteLayout = new Xamarin.Forms.AbsoluteLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                // Padding = new Thickness(5, Device.OnPlatform(20, 0, 0), 5, 5),
                Padding = new Thickness(5, 5, 5, 5),                    // given tool bar don't need upper padding

                BackgroundColor = Color.White
            };
            absoluteLayout.Children.Add(relativeLayout,
                                        new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All
                                        );

            #endregion

            Content = absoluteLayout;
        }
        public CSharpAbsoluteLayout()
        {
            InitializeComponent();

            var absoluteLayout = new Xamarin.Forms.AbsoluteLayout();

            //LayoutBounds X,Y,Width,Height 为比例(最大1)
            var stackLayout_1 = new Xamarin.Forms.StackLayout();

            stackLayout_1.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_1.Children.Add(new Label()
            {
                Text = "0,0,0.3,0.1,All"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_1, new Rectangle(0, 0, 0.3, 0.1));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_1, AbsoluteLayoutFlags.All);
            absoluteLayout.Children.Add(stackLayout_1);

            //LayoutBounds X,Y,Width,Height 为绝对值
            var stackLayout_2 = new Xamarin.Forms.StackLayout();

            stackLayout_2.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_2.Children.Add(new Label()
            {
                Text = "100,100,150,25,None"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_2, new Rectangle(100, 100, 150, 25));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_2, AbsoluteLayoutFlags.None);
            absoluteLayout.Children.Add(stackLayout_2);

            //LayoutBounds Width 为比例,X,Y,Height 为绝对值
            var stackLayout_3 = new Xamarin.Forms.StackLayout();

            stackLayout_3.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_3.Children.Add(new Label()
            {
                Text = "100,130,0.7,30,WidthProportional"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_3, new Rectangle(100, 130, 0.7, 30));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_3, AbsoluteLayoutFlags.WidthProportional);
            absoluteLayout.Children.Add(stackLayout_3);

            //LayoutBounds Height为比例,X,Y,Width 为绝对值
            var stackLayout_4 = new Xamarin.Forms.StackLayout();

            stackLayout_4.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_4.Children.Add(new Label()
            {
                Text = "20,180,260,0.05,HeightProportional"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_4, new Rectangle(20, 180, 260, 0.05));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_4, AbsoluteLayoutFlags.HeightProportional);
            absoluteLayout.Children.Add(stackLayout_4);

            //LayoutBounds X 为比例,Y,Width,Height 为绝对值
            var stackLayout_5 = new Xamarin.Forms.StackLayout();

            stackLayout_5.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_5.Children.Add(new Label()
            {
                Text = "0.6,250,330,30,XProportional"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_5, new Rectangle(0.6, 250, 330, 30));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_5, AbsoluteLayoutFlags.XProportional);
            absoluteLayout.Children.Add(stackLayout_5);

            //LayoutBounds Y 为比例,X,Width,Height 为绝对值
            var stackLayout_6 = new Xamarin.Forms.StackLayout();

            stackLayout_6.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_6.Children.Add(new Label()
            {
                Text = "0,0.45,260,30,YProportional"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_6, new Rectangle(0, 0.45, 260, 30));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_6, AbsoluteLayoutFlags.YProportional);
            absoluteLayout.Children.Add(stackLayout_6);

            //LayoutBounds X,Y 为比例,Width,Height 为绝对值
            var stackLayout_7 = new Xamarin.Forms.StackLayout();

            stackLayout_7.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_7.Children.Add(new Label()
            {
                Text = "0.01,0.5,260,30,PositionProportional"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_7, new Rectangle(0.01, 0.5, 260, 30));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_7, AbsoluteLayoutFlags.PositionProportional);
            absoluteLayout.Children.Add(stackLayout_7);

            //LayoutBounds Width,Height 为比例,X,Y 为绝对值
            var stackLayout_8 = new Xamarin.Forms.StackLayout();

            stackLayout_8.BackgroundColor = Color.FromHex("#f9d33c");
            stackLayout_8.Children.Add(new Label()
            {
                Text = "10,400,0.5,0.05,SizeProportional"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_8, new Rectangle(10, 400, 0.5, 0.05));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_8, AbsoluteLayoutFlags.SizeProportional);
            absoluteLayout.Children.Add(stackLayout_8);

            //AbsoluteLayout可以重叠,先Render的被后Render的元素覆盖
            var stackLayout_9 = new Xamarin.Forms.StackLayout();

            stackLayout_9.BackgroundColor = Color.Red;
            stackLayout_9.Children.Add(new Label()
            {
                Text = "AbsoluteLayout可以重叠"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_9, new Rectangle(10, 450, 0.5, 0.05));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_9, AbsoluteLayoutFlags.SizeProportional);
            absoluteLayout.Children.Add(stackLayout_9);

            var stackLayout_10 = new Xamarin.Forms.StackLayout();

            stackLayout_10.BackgroundColor = Color.Blue;
            stackLayout_10.Children.Add(new Label()
            {
                Text = "AbsoluteLayout可以重叠"
            });
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(stackLayout_10, new Rectangle(10, 460, 0.5, 0.05));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(stackLayout_10, AbsoluteLayoutFlags.SizeProportional);
            absoluteLayout.Children.Add(stackLayout_10);

            Content = absoluteLayout;
        }
Exemplo n.º 6
0
        public PanGesturePage()
        {
            var button = new Button {
                BackgroundColor = Color.Pink,
                Text            = "Hello",
                BorderColor     = Color.Blue,
                BorderWidth     = 3,
            };

            button.Clicked += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON CLICKED!!!!");


            var buttonListener = FormsGestures.Listener.For(button);

            buttonListener.Down += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON DOWN [" + e.Touches[0] + "]");          // does not work with UIControl derived elements

            buttonListener.LongPressing += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON LONG PRESSING [" + e.Touches[0] + "]");
            buttonListener.Panning      += (sender, e) => {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PANNING [" + e.Touches[0] + "]");
                button.TranslationX += e.DeltaDistance.X;
                button.TranslationY += e.DeltaDistance.Y;
            };
            buttonListener.Pinching += (sender, e) => {
                System.Diagnostics.Debug.WriteLine("\tBUTTON PINCHING [" + e.Touches[0] + "]");
                button.Scale *= e.DeltaScale;
            };
            buttonListener.Rotating += (sender, e) => {
                System.Diagnostics.Debug.WriteLine("\tBUTTON ROTATING [" + e.Touches[0] + "]");
                button.Rotation += e.DeltaAngle;
            };

            buttonListener.Up           += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON UP [" + e.Touches[0] + "]");            // does not work with UIControl derived elements
            buttonListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON TAPPED [" + e.Touches[0] + "]");        // does not work with UIControl derived elements
            buttonListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON DOUBLE TAPPED [" + e.Touches[0] + "]"); // does not work with UIControl derived elements

            buttonListener.LongPressed += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON LONG PRESSED [" + e.Touches[0] + "]");
            buttonListener.Panned      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON PANNED TotalDistance=[" + e.TotalDistance + "]");
            buttonListener.Swiped      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON SWIPED!!! Velocity=[" + e.VelocityX + "," + e.VelocityY + "]");

            buttonListener.Pinched += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON PINCHED TotalScale=[" + e.TotalScale + "]");
            buttonListener.Rotated += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBUTTON ROTATED TotalAngle=[" + e.TotalAngle + "]");


            var box = new BoxView {
                BackgroundColor = Color.Green,
            };
            var boxListener = FormsGestures.Listener.For(box);

            //boxListener.Down += OnDown;
            boxListener.Down += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX DOWN [" + e.Touches[0] + "]");

            boxListener.LongPressing += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX LONG PRESSING [" + e.Touches[0] + "]");

            boxListener.Panning += (sender, e) => {
                System.Diagnostics.Debug.WriteLine("\tBOX PANNING [" + e.Touches[0] + "]");
                box.TranslationX += e.DeltaDistance.X;
                box.TranslationY += e.DeltaDistance.Y;
            };

            boxListener.Pinching += (sender, e) => {
                System.Diagnostics.Debug.WriteLine("\tBOX PINCHING [" + e.Touches[0] + "][" + e.DeltaScale + "]");
                box.Scale *= e.DeltaScale;
            };
            boxListener.Rotating += (sender, e) => {
                System.Diagnostics.Debug.WriteLine("\tBOX ROTATING [" + e.Touches[0] + "][" + e.DeltaAngle + "]");
                box.Rotation += e.DeltaAngle;
            };

            boxListener.Up           += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX UP [" + e.Touches[0] + "]");
            boxListener.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX TAPPED [" + e.Touches[0] + "]");
            boxListener.DoubleTapped += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX DOUBLE TAPPED [" + e.Touches[0] + "]");

            boxListener.LongPressed += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX LONG PRESSED [" + e.Touches[0] + "]");
            boxListener.Panned      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX PANNED TotalDistance=[" + e.TotalDistance + "]");
            boxListener.Swiped      += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX SWIPED!!! Velocity=" + e.VelocityX + "," + e.VelocityY + "]");

            boxListener.Pinched += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX PINCHED TotalScale=[" + e.TotalScale + "]");
            boxListener.Rotated += (sender, e) => System.Diagnostics.Debug.WriteLine("\tBOX ROTATED TotalAngle[" + e.TotalAngle + "]");

            relativeLayout = new Xamarin.Forms.RelativeLayout {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(0),
                BackgroundColor   = Color.Transparent,
            };
            relativeLayout.Children.Clear();

            relativeLayout.Children.Add(button,
                                        xConstraint:            Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width / 2); }),
                                        yConstraint:            Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 2); }),
                                        widthConstraint:        Constraint.RelativeToParent((parent) => { return(parent.Width / 8); }),
                                        heightConstraint:       Constraint.RelativeToParent((parent) => { return(parent.Height / 10); })
                                        );
            relativeLayout.Children.Add(box,
                                        xConstraint:            Constraint.RelativeToParent((parent) => { return(parent.X + parent.Width / 4); }),
                                        yConstraint:            Constraint.RelativeToParent((parent) => { return(parent.Y + parent.Height / 4); }),
                                        widthConstraint:        Constraint.RelativeToParent((parent) => { return(parent.Width / 3); }),
                                        heightConstraint:       Constraint.RelativeToParent((parent) => { return(parent.Height / 4); })
                                        );

            absoluteLayout = new Xamarin.Forms.AbsoluteLayout {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                // Padding = new Thickness(5, Device.OnPlatform(20, 0, 0), 5, 5),
                Padding = new Thickness(5, 5, 5, 5),                                                    // given tool bar don't need upper padding

                BackgroundColor = Color.White
            };
            absoluteLayout.Children.Add(relativeLayout,
                                        new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All
                                        );

            Content = absoluteLayout;
        }
        public InputManager(DataSocket socket, Xamarin.Forms.AbsoluteLayout layout, RDPSessionPage rdpSessionPage)
        {
            this.socket         = socket;
            this.layout         = layout;
            this.rdpSessionPage = rdpSessionPage;

            tapViewGestures = new ViewGestures
            {
                BackgroundColor   = Color.Transparent,
                AnimationEffect   = ViewGestures.AnimationType.atNone,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill
            };


/*
 *          tapViewGestures.SwipeRight += (s, e) =>
 *          {
 *              Device.BeginInvokeOnMainThread(() =>
 *              {
 *                  Console.WriteLine("Swipe!");
 *
 *                  inputUpdate(MouseInteractionType.LEFT_DOUBLE_CLICK, -1, -1);
 *              });
 *          };
 *
 *          tapViewGestures.SwipeLeft += (s, e) =>
 *          {
 *              Device.BeginInvokeOnMainThread(() =>
 *              {
 *                  Console.WriteLine("Swipe!");
 *
 *                  inputUpdate(2, -1, -1); //DOWN
 *              });
 *          };
 *          tapViewGestures.SwipeUp += (s, e) =>
 *          {
 *              Device.BeginInvokeOnMainThread(() =>
 *              {
 *                  Console.WriteLine("Swipe!");
 *
 *                  inputUpdate(3, -1, -1); //LEFT
 *              });
 *          };
 *          tapViewGestures.SwipeDown += (s, e) =>
 *          {
 *              Device.BeginInvokeOnMainThread(() =>
 *              {
 *                  Console.WriteLine("Swipe!");
 *
 *                  inputUpdate(4, -1, -1); //RIGHT
 *              });
 *          };
 */
            tapViewGestures.Tap += (s, e) =>
            {
                long cur  = Utils.getUnixTime();
                long diff = cur - lastTapAtUnixTime;
                lastTapAtUnixTime = cur;
                Console.WriteLine("Tap_diff {0}", diff);
                if (diff <= 2) //短い間隔でタップが複数回行われていた場合
                {
                    Task.Run(() =>
                    {
                        Console.WriteLine("Double Tap!");

                        inputUpdate(MouseInteractionType.LEFT_DOUBLE_CLICK, -1, -1);
                    });
                }
                else
                {
                    Task.Run(() =>
                    {
                        Console.WriteLine("Tap!");

                        inputUpdate(MouseInteractionType.LEFT_CLICK, -1, -1); // left click
                    });
                }
            };
            tapViewGestures.LongTap += (s, e) =>
            {
                Task.Run(() =>
                {
                    Console.WriteLine("Long Tap!");

                    inputUpdate(MouseInteractionType.RIGHT_CLICK, -1, -1); // right click
                });
            };
            tapViewGestures.Drag += (s, e) =>
            {
                DragEventArgs moved = (DragEventArgs)e;
                Task.Run(() =>
                {
                    Console.WriteLine("Drag!");

                    inputUpdate(MouseInteractionType.POSITION_SET, (int)moved.DistanceX, (int)moved.DistanceY); // Drag
                });
            };

            tapViewGestures.TouchBegan += (s, e) =>
            {
                orgPosXDragStart = int.MaxValue;
                orgPosYDragStart = int.MaxValue;
            };
        }
Exemplo n.º 8
0
 public AbsoluteElementCollection(ObservableCollection <Element> inner, AbsoluteLayout parent) : base(inner)
 {
     Parent = parent;
 }