2017-01-04 85 views
1

在我的Xamarin Forms應用程序中,我試圖在移動界面上放置兩個標籤,一個放在左下角,一個放在右下角。Xamarin佈局如何在屏幕的左下角和右下角放置標籤

這是我目前的嘗試。這是一個網格佈局與一排兩列,在每個單元的標籤,左某與HorizontalTextAlightment="Start"HorizontalTextAlightment="End"

...other unrelated controls... 
    <StackLayout Orientation="Horizontal" Spacing="0" Padding="15" VerticalOptions="End" > 
     <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <Label Text="{Binding DeviceId}" HorizontalTextAlignment="Start" Grid.Row="0" Grid.Column="0" /> 
     <Label Text="{Binding Version}" HorizontalTextAlignment="End" Grid.Row="0" Grid.Column="1" /> 
     </Grid> 


    </StackLayout> 

    </StackLayout> 

正確的

這產生了這種不需要的結果:(v1.0-1應該對齊到右邊)

current

這就是我想要的東西:

enter image description here

+0

嘗試使用Horizo​​ntalOptions作爲StartAndExpand的第一個標籤和EndAndExpand的第二個標籤,而不是Horizo​​ntalTextAlignment – Mounika

回答

2

你爲什麼包裹在一個StackLayout有何看法? A Stacklayout將分配所需的最小空間量。這就是爲什麼你看到你在截圖1

所示的行爲,如果你只是有:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <Label Text="{Binding DeviceId}" HorizontalTextAlignment="Start" Grid.Row="0" Grid.Column="0" /> 
    <Label Text="{Binding Version}" HorizontalTextAlignment="End" Grid.Row="0" Grid.Column="1" /> 
    </Grid> 

你會看到所期望的行爲。

您也可以嘗試在Label使用HorizontalOptions代替HorizontalTextAlignment


如果你真的需要使用StackLayout你可以嘗試設置的StackLayoutFillAndExpandHorizontalOptions。其中規定:

FillAndExpand - 地點視圖,以便它沒有填充和佔用 儘可能多的空間佈局將賦予它。

裁判:https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/stack-layout/#Sizing

0

使用「*」爲寬度僅使大列,因爲它需要在以適應其內容。相反,嘗試使每列的總寬度的50%。

 <ColumnDefinition Width="50*" /> 
     <ColumnDefinition Width="50*" /> 
+0

我認爲' 「#*」'僅被解釋爲與其他兄弟行(或列)相比的比率 –

2

試試這個

<Grid> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="Auto" /> 
    <ColumnDefinition Width="*" /> 
    <ColumnDefinition Width="Auto" /> 
    </Grid.ColumnDefinitions> 
    <Label Text="{Binding DeviceId}" HorizontalTextAlignment="Start" Grid.Row="1" Grid.Column="0" /> 
    <Label Text="{Binding Version}" HorizontalTextAlignment="End" Grid.Row="1" Grid.Column="2" /> 
</Grid> 
相關問題