#c# #xaml #xamarin #xamarin.forms
Вопрос:
Я создал горизонталь ScrollView
, и в ней я создал рамку. Я создал второй кадр для каждого столбца, но между кадром и рамкой каждого столбца было огромное расстояние. Как я могу удалить расстояние между основной рамкой и рамкой каждого столбца ?
Код:
<Frame
BorderColor="Black"
CornerRadius="10"
HasShadow="True"
BackgroundColor="Transparent">
<ScrollView
BackgroundColor="Transparent"
Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<StackLayout
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Grid BackgroundColor="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Frame Grid.Column="0"
BorderColor="black"
BackgroundColor="Transparent">
<StackLayout>
<Label x:Name="DayForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="0"
Grid.Column="0"
TextColor="#eeff00"/>
<Label x:Name="TempDayForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="1"
Grid.Column="0"
TextColor="#eeff00"/>
<Label Text="Min °C"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="2"
Grid.Column="0"
TextColor="#0025f7"/>
<Label x:Name="MinTempDayForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="3"
Grid.Column="0"
TextColor="#0025f7"/>
<Label Text="Max °C"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="4"
Grid.Column="0"
TextColor="#ff0000"/>
<Label x:Name="MaxTempDayForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="5"
Grid.Column="0"
TextColor="#ff0000"/>
<Image x:Name="IconChanceOf5DaysForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
Grid.Row="6"
Grid.Column="0"/>
<Label x:Name="ChanceOf5DaysForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="7"
Grid.Column="0"/>
<Image x:Name="IconWind5DaysForecast1"
VerticalOptions="Center"
HorizontalOptions="Center"
Grid.Row="8"
Grid.Column="0"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].WindForecast.WindForecastValue, StringFormat='{0:0}m/s'}"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="9"
Grid.Column="0"/>
</StackLayout>
</Frame>
<Frame Grid.Column="1"
BorderColor="black"
BackgroundColor="Transparent">
<StackLayout>
<Label x:Name="DayForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="0"
Grid.Column="1"
TextColor="#eeff00"/>
<Label x:Name="TempDayForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="1"
Grid.Column="1"
TextColor="#eeff00"/>
<Label Text="Min °C"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="2"
Grid.Column="1"
TextColor="#0025f7"/>
<Label x:Name="MinTempDayForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="3"
Grid.Column="1"
TextColor="#0025f7"/>
<Label Text="Max °C"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="4"
Grid.Column="1"
TextColor="#ff0000"/>
<Label x:Name="MaxTempDayForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="5"
Grid.Column="1"
TextColor="#ff0000"/>
<Image x:Name="IconChanceOf5DaysForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
Grid.Row="6"
Grid.Column="1"/>
<Label x:Name="ChanceOf5DaysForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="7"
Grid.Column="1"/>
<Image x:Name="IconWind5DaysForecast2"
VerticalOptions="Center"
HorizontalOptions="Center"
Grid.Row="8"
Grid.Column="1"/>
<Label Text="{Binding WeatherDataForecastHourly.List[8].WindForecast.WindForecastValue, StringFormat='{0:0}m/s'}"
VerticalOptions="Center"
HorizontalOptions="Center"
VerticalTextAlignment="Center"
Style="{StaticResource labelStyle}"
FontAttributes="Bold"
Grid.Row="9"
Grid.Column="1"/>
</StackLayout>
</Frame>
</StackLayout>
</ScrollView>
</Frame>
Я создал 10 строк по 5 столбцов, но когда я поставил внутренние рамки, появилось огромное расстояние.
Комментарии:
1. Вы пробовали установить заполнение=»0″ на основной раме ?
2. При оставлении только одного <Высота определения строки=» » /> все в порядке, но когда я ставлю другие 9 ><Высота определения строки=» » /> Заполнение=»0″ не работает
Ответ №1:
Как я могу удалить расстояние между основной рамкой и рамкой каждого столбца ?
Из Сетки.Свойство ColumnSpacing, пространство между столбцами в этом макете сетки. Значение по умолчанию равно 6.
Таким образом, вы можете настроить ColumnSpacing="0"
сетку. Это будет работать нормально.
<Grid BackgroundColor="Transparent" ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
Ответ №2:
из документов
Рамка имеет отступ по умолчанию 20.
StackLayout
также имеет значение интервала по умолчанию. Вам нужно будет поиграть со значениями отступов, полей и интервалов, чтобы получить желаемый эффект