浮动StackLayout xamarin表单

时间:2017-08-10 20:44:59

标签: xaml xamarin xamarin.forms

我希望在我的内容中有一个'StackLayout'固定并浮动,它将包含4个'Button'。

目前我的布局是assikm

     <?xml version="1.0" encoding="utf-8" ?>
       <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         Title="teste">


   <Grid>
        <ScrollView BackgroundColor="#ffffff" Padding="15" Grid.Row="0">
        <StackLayout HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
            <Label Text="{Binding Titulo}"  VerticalTextAlignment="Center" HorizontalTextAlignment="Center" TextColor="#38B6AB" FontSize="22" FontAttributes="Bold"/>
            <Label Text="{Binding Data}"  VerticalTextAlignment="Center" HorizontalTextAlignment="Center" TextColor="#5a5a5a" FontSize="18"  FontAttributes="Bold"/>

            <Image x:Name="imagen1" Source="{Binding ImageSource}" Aspect="AspectFit">
                <Image.GestureRecognizers>
                    <TapGestureRecognizer
                    Tapped="OnTapped" />
                </Image.GestureRecognizers>
            </Image>

        </StackLayout>
    </ScrollView>
</Grid>
//-----Floating button----- //

1 个答案:

答案 0 :(得分:1)

Grid可以通过将项放在同一行和列中来将事物置于其他事物之上,如下所示。我将注意到,根据您放置Button的方式,将Button放置在用户想要滚动的位置可能是一个可用性问题。

<Grid>

  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions> <!-- Multiple columns will allow even Button spacing, just set Grid.ColumnSpan on your ScrollView -->
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>

  <ScrollView BackgroundColor="#ffffff"
              Padding="15"
              Grid.Row="0"
              Grid.Column="0"
              Grid.ColumnSpan="4">
    <StackLayout HorizontalOptions="Fill"
                 VerticalOptions="FillAndExpand">
            ....                
    </StackLayout>
  </ScrollView>

  <Button Text="One"
          Grid.Row="0"
          Grid.Column="0"/>

  <Button Text="Two"
          Grid.Row="0"
          Grid.Column="1"/>

  <Button Text="Three"
          Grid.Row="0"
          Grid.Column="2"/>

  <Button Text="Four"
          Grid.Row="0"
          Grid.Column="3"/>
</Grid>