【问题标题】:Xamarin stack layout overlapping sectionsXamarin 堆栈布局重叠部分
【发布时间】:2019-08-13 16:49:52
【问题描述】:

我在 Xamarin 中相对较新,我正在尝试创建一个表单。

当没有包含其他stacklayout时,第一个stacklayout显示OKhttp://prntscr.com/os7703

添加第二个堆栈布局后,我得到了这个http://prntscr.com/os733e

这是我正在使用的代码:

<ContentPage.Content>
        <StackLayout>
            <grial:TabControl>
                <grial:TabItem Text="Fuel Setup">
                    <Grid>
                        <StackLayout Margin="10,10,10,10" HeightRequest="60" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                            <Stepper Maximum="360" Increment="1" HorizontalOptions="Center" ValueChanged="Stepper_ValueChanged" VerticalOptions="StartAndExpand" />
                            <Label x:Name="lblGallons" Text="Gallons" />
                            <Entry x:Name="txtGallons" WidthRequest="130" />
                        </StackLayout>
                        <StackLayout HorizontalOptions="FillAndExpand" HeightRequest="300">
                            <Editor x:Name="txtNotes" VerticalOptions="Center" />
                        </StackLayout>-->
                    </Grid>
                </grial:TabItem>
            </grial:TabControl>
        </StackLayout>
    </ContentPage.Content>

每个视图是否只需要一个堆栈布局,或者其他东西对于获取重叠控件是“有罪的”?

【问题讨论】:

  • 您有一个没有定义行或列的网格,因此该网格中的每个项目都将彼此重叠
  • 谢谢@Jason 你能告诉我我应该纠正什么

标签: xamarin xamarin.forms stacklayout


【解决方案1】:

如果您想在 Grid 中进行此布局,请尝试以下代码。

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="55" ></RowDefinition>
            <RowDefinition Height="55" ></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="180"></ColumnDefinition>
            <ColumnDefinition Width="50"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Stepper Grid.Row="0" Grid.Column="0"  Maximum="360" Increment="1" HorizontalOptions="Center" VerticalOptions="StartAndExpand"/>
        <Label Grid.Row="0" Grid.Column="1" x:Name="lblGallons" Text="Gallons" />
        <Entry Grid.Row="0" Grid.Column="2" x:Name="txtGallons" WidthRequest="50" />
        <Editor Grid.Row="1" Grid.Column="0" x:Name="txtNotes" VerticalOptions="Center"></Editor>
    </Grid>

注意:使用 Grid 时,需要先用RowDefinition 和ColumnDefinition 定义行和列。然后使用Grid.Row和Grid.Column指定行列。

【讨论】:

    【解决方案2】:

    如果您只想让您的项目垂直堆叠,只需 StackLayout 而不是 grid

    <StackLayout>
      <StackLayout Margin="10,10,10,10" HeightRequest="60" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
        <Stepper Maximum="360" Increment="1" HorizontalOptions="Center" ValueChanged="Stepper_ValueChanged" VerticalOptions="StartAndExpand" />
        <Label x:Name="lblGallons" Text="Gallons" />
        <Entry x:Name="txtGallons" WidthRequest="130" />
      </StackLayout>
      <StackLayout HorizontalOptions="FillAndExpand" HeightRequest="300">
        <Editor x:Name="txtNotes" VerticalOptions="Center" />
      </StackLayout>-->
    </StackLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      相关资源
      最近更新 更多