我正在使用 Grid.ColumnDefinition 但百分比似乎无法在 Android 上正常工作,而在 Windows 上却可以正常工作。
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Views.TestMapPage"
Title="TestMap">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView Grid.Row="0" Grid.ColumnSpan="3" Color="Blue" />
<BoxView Grid.Row="1" Grid.Column="0" Color="Purple" />
<BoxView Grid.Row="1" Grid.Column="1" Color="Yellow" />
<BoxView Grid.Row="1" Grid.Column="2" Color="Purple" />
<BoxView Grid.Row="2" Grid.ColumnSpan="3" Color="Red" />
</Grid>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
结果并不如预期(20%,60%,20%)
编辑并回答问题:
所以我发现了这个问题,看来Grid.ColumnSpan是错误的根源。如果我尝试不使用它
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Views.TestMapPage"
Title="TestMap">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView Grid.Row="0" Grid.Column="0" Color="Blue" />
<BoxView Grid.Row="1" Grid.Column="0" Color="Purple" />
<BoxView Grid.Row="1" Grid.Column="1" Color="Yellow" />
<BoxView Grid.Row="1" Grid.Column="2" Color="Purple" />
<BoxView Grid.Row="2" Grid.Column="0" Color="Red" />
</Grid>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
我得到以下结果,并且网格按照指定进行分割。
即使在不同的目标架构和略有不同的场景中,该区域也存在错误......
我想在他们修复它之前我别无选择找到解决方法...无论如何我不会在最终的 UI 中使用 BoxView 所以它毕竟可能没问题...
继续编码:D
编辑:它与框架一起正常工作
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Views.TestMapPage"
Title="TestMap">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Frame BorderColor="Gray"
CornerRadius="10"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="3"
BackgroundColor="Blue">
<Label Text="Frame wrapped around a Label" />
</Frame>
<!--<BoxView Grid.Row="0" Grid.Column="0" Color="Blue" />-->
<BoxView Grid.Row="1" Grid.Column="0" Color="Purple" />
<BoxView Grid.Row="1" Grid.Column="1" Color="Yellow" />
<BoxView Grid.Row="1" Grid.Column="2" Color="Purple" />
<BoxView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Color="Red" />
</Grid>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
507 次 |
| 最近记录: |