示例#1
0
        private void BuildLocationLayout(StackLayout main)
        {
            var calendar = new Image();

            calendar.Source        = ImageSource.FromResource("TiroApp.Images.calendar.png");
            calendar.HeightRequest = 20;
            calendar.WidthRequest  = 22;
            var placeBackground = new Image();

            placeBackground.Source        = ImageSource.FromResource("TiroApp.Images.searchBackground.png");
            placeBackground.Aspect        = Aspect.Fill;
            placeBackground.HeightRequest = 44;

            var locationACEntry = new AutoCompleteView();

            locationEntry                  = locationACEntry.EntryText;
            locationEntry.FontFamily       = UIUtils.FONT_SFUIDISPLAY_LIGHT;
            locationEntry.WidthRequest     = 250;
            locationEntry.HeightRequest    = 38;
            locationEntry.FontSize         = 16;
            locationEntry.BackgroundColor  = Color.White;
            locationEntry.Placeholder      = "Use current location";
            locationEntry.PlaceholderColor = Color.Black;
            locationEntry.TextColor        = Color.Black;
            locationEntry.Focused         += (o, a) => { locationEntry.Text = ""; };
            var sh = new PlaceSearchHelper(locationACEntry);

            sh.OnSelected += (o, p) =>
            {
                LocationFilter = new LocationFilter()
                {
                    Lat    = p.Latitude,
                    Lon    = p.Longitude,
                    Radius = RADIUS
                };
                LocationAddress = locationEntry.Text;
            };

            var rl = new RelativeLayout();

            rl.Margin            = new Thickness(0, 10, 0, 10);
            rl.WidthRequest      = Device.OnPlatform(300, 320, 300);
            rl.VerticalOptions   = LayoutOptions.Start;
            rl.HorizontalOptions = LayoutOptions.Center;
            rl.Children.Add(placeBackground, Constraint.Constant(0), Constraint.Constant(0),
                            Constraint.RelativeToParent(p => p.Width), Constraint.Constant(placeBackground.HeightRequest));
            rl.Children.Add(calendar, Constraint.Constant(10), Constraint.Constant(10));
            rl.Children.Add(locationACEntry, Constraint.Constant(40), Constraint.Constant(4));
            //heightConstraint: Constraint.Constant(locationEntry.HeightRequest));

            var useCurrLocation = new CustomLabel()
            {
                HorizontalOptions = LayoutOptions.Center,
                Text                    = "Use Current Location",
                TextColor               = Props.ButtonColor,
                BackgroundColor         = Color.White,
                VerticalOptions         = LayoutOptions.Center,
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize                = 17,
                FontFamily              = UIUtils.FONT_SFUIDISPLAY_LIGHT,
            };

            useCurrLocation.GestureRecognizers.Add(new TapGestureRecognizer(LocationClicked));

            main.Children.Add(useCurrLocation);
            main.Children.Add(rl);
            var separator = UIUtils.MakeSeparator(true);

            separator.VerticalOptions = LayoutOptions.Start;
            main.Children.Add(separator);
        }