【问题标题】:Floating StackLayout xamarin forms浮动 StackLayout xamarin 表单
【发布时间】:2018-01-19 06:16:25
【问题描述】:

我希望在我的内容中固定并浮动一个“StackLayout”,它将包含 4 个“按钮”。

我现在的布局是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----- //

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    Grid 可以通过将项目放置在同一行和同一列中,将项目浮动到其他项目之上,如下所示。我会注意到,根据您放置Buttons 的方式,将Buttons 放置在用户应该滚动的位置可能是一个可用性问题。

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

    【讨论】:

    • 2个错误,按钮占据了所有内容,scrowview无法移动,另一个错误和按钮在中心,更正并出现在页脚中
    • @José 您没有指定您想要Buttons 的位置。这只是向您展示如何做到这一点的起点。随意调整它,直到你想要你想要的。它并不意味着是一个解决方案,而是旨在帮助您学习如何做到这一点。如果您无法按照自己想要的方式定位它们,请告诉我或发布新问题,
    • 好的,我定位有困难是的,我再开个问
    猜你喜欢
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2016-09-07
    • 2017-05-04
    • 2019-08-18
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多