José
José

Reputation: 165

Floating StackLayout xamarin forms

I want in my content to have a 'StackLayout' fixed and floating where it will contain 4 'Button's.

My layout is assikm at the moment

     <?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----- //

Upvotes: 0

Views: 1232

Answers (1)

hvaughan3
hvaughan3

Reputation: 11105

The Grid can float things on top of other things by placing the item in the same row and column, like the following. I will note that, depending on how you place the Buttons, it might be a usability issue to place Buttons where the user is suppose to be scrolling.

<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>

Upvotes: 2

Related Questions