14
我有這個代碼,這是目前的組合和如何更改<StackLayout><Grid>屏幕以使用<RelativeLayout>?
我想移動到相對佈局,並沒有看到這麼多的例子。希望對此有何建議可以完成。
關於XAML的一些觀點。
- 要麼emptyGrid或phraseGrid出現在屏幕
- 要麼buttonGrid或tapGrid出現在屏幕
- 按鈕的垂直中心和抽頭標籤應該是相同的位置上。因此,當按鈕沒有顯示時,輕擊標籤會出現在與按鈕相同的垂直按鈕上。
- 出現方框一個標籤頁
裏面我知道這是不是一個簡單的問題多一點,但我敢肯定,這將是感興趣的人。由於答案可能會涉及到,我會在幾天內爲此打開250點的獎勵。
<Grid x:Name="emptyGrid" Grid.Row="1" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout Padding="10,0,10,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label x:Name="emptyLabel" FontSize="18" XAlign="Center" TextColor="Gray" />
</StackLayout>
<Button x:Name="resetButton" Text="Reset points?" TextColor="White" FontAttributes="Bold" FontSize="20" HeightRequest="60" BackgroundColor="#E19A3F" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand">
<Button.FontSize>
<OnPlatform x:TypeArguments="x:Double" iOS="25" Android="20" />
</Button.FontSize>
</Button>
</Grid>
<Grid x:Name="phraseGrid" Padding="20, 20, 20, 20" BackgroundColor="Transparent" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="6*" />
<RowDefinition Height="6*" />
<RowDefinition Height="80*" />
<RowDefinition Height="13*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid x:Name="prGrid" Grid.Row="0" Grid.Column="0"
Padding="5,0,0,0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
BackgroundColor>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="50*" />
</Grid.ColumnDefinitions>
<Label x:Name="msg1" Style="{StaticResource smallLabel}" Text="msg1" Grid.Row="0" Grid.Column="0" />
<Label x:Name="msg2" Style="{StaticResource smallLabel}" Text="msg2" Grid.Row="0" Grid.Column="1" />
<Label x:Name="msg3" Style="{StaticResource smallLabel}" Text="msg3" Grid.Row="0" Grid.Column="2" />
</Grid>
<Grid x:Name="siGrid" Grid.Row="1" Grid.Column="0"
Padding="5,0,0,0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="50*" />
</Grid.ColumnDefinitions>
<Label x:Name="faveLabel" Style="{StaticResource smallLabel}" FontFamily="FontAwesome" Grid.Row="0" Grid.Column="0" />
<Label x:Name="wordTypeLabel" Style="{StaticResource smallLeftLabel}" Grid.Row="0" Grid.Column="1" />
</Grid>
<Grid x:Name="wordGrid" Grid.Row="2" Grid.Column="0"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="45*" />
<RowDefinition Height="55*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label x:Name="textLabel" FontSize="45" XAlign="Center" VerticalOptions="Center" LineBreakMode="WordWrap" />
</Grid>
<Grid x:Name="detailGrid" Grid.Row="1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="10,0,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label x:Name="detail1" Grid.Row="0" Style="{StaticResource bigLabel}" />
<Label x:Name="detail2" Grid.Row="1" Style="{StaticResource bigLabel}" />
<Label x:Name="detail3" Grid.Row="2" Style="{StaticResource bigLabel}" />
</Grid>
</Grid>
<Grid x:Name="buttonGrid" Grid.Row="3" Grid.Column="0"
HorizontalOptions="FillAndExpand" VerticalOptions="Center" Padding="20, 0">
<Button x:Name="aButton" Style="{StaticResource pointButton}" Grid.Column="0" Text="0">
</Button>
<Button x:Name="bButton" Style="{StaticResource pointButton}" Grid.Column="1" Text="1">
</Button>
<Button x:Name="cButton" Style="{StaticResource pointButton}" Grid.Column="2" Text="2">
</Button>
<Button x:Name="dButton" Style="{StaticResource pointButton}" Grid.Column="3" Text="5">
</Button>
</Grid>
<Grid x:Name="tapGrid" Grid.Row="3" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<Label x:Name="tapScreenLabel" Style="{StaticResource smallLabel}" />
</Grid>
</Grid>
</StackLayout>
不要使用相對佈局爲傑森 - 史密斯代替建議使用絕對佈局,它具有更好的性能。 –
您有任何鏈接可以解釋更多關於此的信息。我不確定性能會成爲問題,因爲它只是一個簡單的頁面應用程序,並沒有太大的改變。想向你學習更多。我想要親戚的原因是因爲我希望佈局隨着屏幕尺寸的變化而改變。謝謝 – Alan2
我正要給你Adam的J狼博客佈局食譜,但似乎他不再有博客(出於某種原因)。關於相對佈局與絕對佈局,您可以對兩種佈局執行相同的操作,即使性能不是您應該關注的問題,您應該查看一下,以下是一些有用的鏈接: https://kimsereyblog.blogspot.mx/ 2016/09/absolute-layout-and-relative-layout.html https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/absolute-layout/ https://www.youtube .com/watch?v = NDOOr29pCng –