问题描述
我有水平 function test() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange('O1:O28');
var value = range.getValue();
browser.msgBox(value);
};
并且里面我有 5 个垂直框架。在每个人ScrollView
中,我都放了一张图片作为背景。如何在每个 StackLayout
中将 StackLayout
中的元素居中。
我将粘贴第一帧的代码:
Frame
我有两个问题:
-
首先是如何将每个
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <Grid BackgroundColor="Transparent"> <Grid.RowDeFinitions> <RowDeFinition Height="*" /> </Grid.RowDeFinitions> <Grid.ColumnDeFinitions> <ColumnDeFinition Width="*" /> <ColumnDeFinition Width="*" /> <ColumnDeFinition Width="*" /> <ColumnDeFinition Width="*" /> <ColumnDeFinition Width="*" /> </Grid.ColumnDeFinitions> <Frame Grid.Column="0" BorderColor="White" Margin="10,10,0" CornerRadius="10" BackgroundColor="Transparent"> <RelativeLayout> <Image x:Name="ImageForecast1" Aspect="AspectFill" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativetoParent,Property=Height,Factor=1}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativetoParent,Property=Width,Factor=1}"/> <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="#00ccff"/> <Label x:Name="MinTempDayForecast1" VerticalOptions="Center" HorizontalOptions="Center" VerticalTextAlignment="Center" Style="{StaticResource labelStyle}" FontAttributes="Bold" Grid.Row="3" Grid.Column="0" TextColor="#00ccff"/> <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"/> <Image x:Name="IconClouds5DaysForecast1" VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="10" Grid.Column="0"/> <Label Text="{Binding WeatherDataForecastHourly.List[0].CloudsForecast.CloudsForecastValue,StringFormat='{0:0}%'}" VerticalOptions="Center" HorizontalOptions="Center" VerticalTextAlignment="Center" Style="{StaticResource labelStyle}" FontAttributes="Bold" Grid.Row="11" Grid.Column="0"/> <Image x:Name="IconRain5DaysForecast1" VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="12" Grid.Column="0"/> <Label Text="{Binding WeatherDataForecastHourly.List[0].RainForecast.RainForecastValue,StringFormat='{0}mm'}" VerticalOptions="Center" HorizontalOptions="Center" VerticalTextAlignment="Center" Style="{StaticResource labelStyle}" FontAttributes="Bold" Grid.Row="13" Grid.Column="0"/> <Image x:Name="IconSNow5DaysForecast1" VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="14" Grid.Column="0"/> <Label Text="{Binding WeatherDataForecastHourly.List[0].SNowForecast.SNowForecastValue,StringFormat='{0}mm'}" VerticalOptions="Center" HorizontalOptions="Center" VerticalTextAlignment="Center" Style="{StaticResource labelStyle}" FontAttributes="Bold" Grid.Row="15" Grid.Column="0"/> </StackLayout> </RelativeLayout> </Frame>
和Frame
中的元素居中? -
我的第二个问题是为什么每次单击按钮后所有框架都会水平展开,我该如何解决这个问题?
我会在点击几下按钮后上传截图:
解决方法
首先是如何让每个Frame和StackLayout中的元素居中 ?
只需在 StackLayout
中加入您为图像设置的相同约束:
<StackLayout RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=1}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1}">
<Label x:Name="DayForecast1"
...
</StackLayout>
它对我有用:
我的第二个问题是为什么每次单击按钮后所有帧 水平展开,我该如何解决这个问题?
你已经问过了here。