【问题标题】:Button over map Xamarin forms地图 Xamarin 表单上的按钮
【发布时间】:2018-11-01 15:54:18
【问题描述】:

我正在使用 Xamarin Forms 来编写我的应用程序。 我想在我的地图上方添加一个按钮(图中红色圆圈)打开另一个页面:go to the image

这是我在xaml页面上写的代码:

<ContentPage.ToolbarItems>
    <ToolbarItem Icon="search.png" Clicked="SearchClicked" />
</ContentPage.ToolbarItems>

 <ContentView Content="{Binding Map}" ></ContentView>

你能帮帮我吗?谢谢!

【问题讨论】:

    标签: google-maps xaml button xamarin.forms


    【解决方案1】:

    要在页面内容上放置一个按钮,我会查看AbsoluteLayout。您应该能够在 XAML 中执行以下操作。

    <AbsoluteLayout>
      <ContentView Content="{Binding Map}" 
                   AbsoluteLayout.LayoutBounds="0,0,1,1"
                   AbsoluteLayout.LayoutFlags="All" 
                   HorizontalOptions="FillAndExpand"
                   VerticalOptions="FillAndExpand" />
      <Button AbsoluteLayout.LayoutBounds="0, 1, AutoSize, AutoSize"
              AbsoluteLayout.LayoutFlags="PositionProportional"
              HeightRequest="50"
              WidthRequest="50"
              CornerRadius="25" />
    </AbsoluteLayout>
    

    这是未经测试的,可能需要一些调整,但应该会给你一些可以构建的东西。

    【讨论】:

    • 有效!我使用了 AbsoluteLayout 但它没有用。您的解决方案没问题,谢谢!
    • @Riccardo 你为解决这个问题做了什么?
    【解决方案2】:

    假设您使用的是Xamarin.Forms.Maps,您可以实现以下(或类似的):

    <Grid
        VerticalOptions="FillAndExpand">
        <map:Map
            IsShowingUser="True"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand"
            MapType="Hybrid"/>
        <AbsoluteLayout
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand">
            <!-- Insert your circle control below. Using BoxView as example -->
            <BoxView
                AbsoluteLayout.AbsoluteBounds="0.1, 0.9, 20, 20"
                AbsoluteLayout.AbsoluteFlags="PositionProportional"
                BackgroundColor="Red">
                <BoxView.GestureRecognizer>
                    <TapGestureRecognizer
                        Tapped="OnCircleTap"/> <!-- Replace with your event -->
                </BoxView.GestureRecognizer/>
            </BoxView>
        </AbsoluteLayout>
    </Grid>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      相关资源
      最近更新 更多