大佬教程收集整理的这篇文章主要介绍了如何使用图像背景填充 StackLayout 到最后并使用 xamarin 删除网格之间的间距,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想拉伸整个 StackLayout 的图片,但它拉伸到中间。我还想减少网格中行和列之间的距离。 我的代码:
<Frame
bordercolor="White"
margin="10,10,0"
CornerRadius="10"
HasShadow="True"
BACkgroundcolor="transparent">
<relativeLayout>
<Image
Aspect="AspectFill"
relativeLayout.HeightConsTraint="{ConsTraintexpression Type=relativetoparent,Property=Height,Factor=0.5}"
relativeLayout.WIDthConsTraint="{ConsTraintexpression Type=relativetoparent,Property=WIDth,Factor=1}"
source="https://www.4freephotos.com/medium/batch/Scattered-clouds276.jpg" />
<StackLayout>
<Label x:name="datetiR_392_11845@eForecast1"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
VerticalOptions="Center"
FontSize="14"/>
<Label x:name="datetiR_392_11845@eForecast2"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
FontSize="14"/>
<GrID BACkgroundcolor="transparent"
padding="0,0">
<GrID.RowDeFinitions>
<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>
<Image x:name="IconForecast11"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="0"
GrID.column="0"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].WeatherForecast[0].DescriptionForecast}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="1"
GrID.column="0"
FontSize="14"/>
<Image x:name="IconForecast12"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="0"
GrID.column="1"/>
<Label x:name="AvgTempForecastDay1"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="1"
GrID.column="1"
FontSize="14"/>
<Image x:name="IconForecast13"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="0"
GrID.column="2"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].WindForecast.WindForecastValue,StringFormat='{0:0}m/s'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="1"
GrID.column="2"
FontSize="14"/>
<Image x:name="IconForecast14"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="0"
GrID.column="3"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].CloudsForecast.CloudsForecastValue,StringFormat='{0:0}%'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="1"
GrID.column="3"
FontSize="14"/>
<Image x:name="IconForecast15"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="0"
GrID.column="4"/>
<Label x:name="ChanceOfRainForecast1"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="1"
GrID.column="4"
FontSize="14"/>
<Image x:name="IconForecast5Days1"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="2"
GrID.column="0"/>
<Image x:name="IconForecast5Days2"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="2"
GrID.column="1"/>
<Image x:name="IconForecast5Days3"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="2"
GrID.column="2"/>
<Image x:name="IconForecast5Days4"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="2"
GrID.column="3"/>
<Image x:name="IconForecast5Days5"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="2"
GrID.column="4"/>
<Label Text="Feels like"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="3"
GrID.column="0"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].MainForecasts.FeelslikeForecast,StringFormat='{0:0}°C'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="4"
GrID.column="0"
FontSize="14"/>
<Label Text="Min °C"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="3"
GrID.column="1"
FontSize="14"/>
<Label x:name="MinTempForecastDay1"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="4"
GrID.column="1"
FontSize="14"/>
<Label Text="Max °C"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="3"
GrID.column="2"
FontSize="14"/>
<Label x:name="MaxTempForecastDay1"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="4"
GrID.column="2"
FontSize="14"/>
<Label Text="Rain"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="3"
GrID.column="3"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].RainForecast.RainForecastValue,StringFormat='{0}mm'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="4"
GrID.column="3"
FontSize="14"/>
<Label Text="snow"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="3"
GrID.column="4"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].snowForecast.snowForecastValue,StringFormat='{0}mm'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="4"
GrID.column="4"
FontSize="14"/>
<Image x:name="IconForecast5Days26"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="5"
GrID.column="0"/>
<Image x:name="IconForecast5Days27"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="5"
GrID.column="1"/>
<Image x:name="IconForecast5Days28"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="5"
GrID.column="2"/>
<Image x:name="IconForecast5Days29"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="5"
GrID.column="3"/>
<Image x:name="IconForecast5Days30"
VerticalOptions="Center"
HorizontalOptions="Center"
GrID.Row="5"
GrID.column="4"/>
<Label Text="HumIDity"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="6"
GrID.column="0"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].MainForecasts.HumIDityForecast,StringFormat='{0:0}%'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="7"
GrID.column="0"
FontSize="14"/>
<Label Text="Pressure"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="6"
GrID.column="1"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].MainForecasts.PressureForecast,StringFormat='{0:0}mb'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="7"
GrID.column="1"
FontSize="14"/>
<Label Text="Ground"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="6"
GrID.column="2"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].MainForecasts.PressureGroundLevelForecast,StringFormat='{0:0}mb'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="7"
GrID.column="2"
FontSize="14"/>
<Label Text="Sea Level"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="6"
GrID.column="3"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].MainForecasts.SeaLevelForecast,StringFormat='{0:0}mb'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="7"
GrID.column="3"
FontSize="14"/>
<Label Text="Direction"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="6"
GrID.column="4"
FontSize="14"/>
<Label Text="{Binding WeatherDataForecastHourly.List[0].WindForecast.WindDirectionForecastValue,StringFormat='{0:0}°'}"
Style="{Staticresource labelStylE}"
HorizontalTextAlignment="Center"
GrID.Row="7"
GrID.column="4"
FontSize="14"/>
</GrID>
</StackLayout>
</relativeLayout>
</Frame>
使用此代码,图像本身被拉伸到 StackLayout 的中间。 我附上截图:
这也给我留下了一个丑陋的印象,即行和列之间的距离很大。能不能举个例子,如何减少线条之间的距离,如何拉伸整个StackLayout的图片
我想拉伸整个 StackLayout 的图片,但它拉伸到中间。
将图片的高度设置为与父布局相同。
<Image Aspect="AspectFill"
RelativeLayout.HeightConsTraint="{ConsTraintexpression Type=RelativeToParent,Property=Height,Factor=1}"
RelativeLayout.WidthConsTraint="{ConsTraintexpression Type=RelativeToParent,Property=Width,Factor=1}"
source="https://www.4freephotos.com/medium/batch/Scattered-clouds276.jpg" />
我还想减少网格中行和列之间的距离。我的代码:
设置 RowDefinition.Height
为 auto
,*
将占据所有行的整个空间。
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
,
正如 Cole 之前提到的,使用“auto”而不是“*”,也许更多的行会帮助你实现你想要的。
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
...
</Grid.RowDefinitions>
以上是大佬教程为你收集整理的如何使用图像背景填充 StackLayout 到最后并使用 xamarin 删除网格之间的间距全部内容,希望文章能够帮你解决如何使用图像背景填充 StackLayout 到最后并使用 xamarin 删除网格之间的间距所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。