2017-03-29 71 views
0

我有Xamarin Forms項目。在xaml中,我希望在ListView上面有一個可點擊且透明的按鈕(不透明度= 0.9)。 ListView上方有一個標籤,下方有一個標籤。我使用RelativeLayout來放置ListView和透明按鈕,並用兩個標籤將其包裝在StackLayout中。問題是ListView超出頁面擴展。在ListView上放置按鈕擴展超出頁面

這裏是我的XAML文件代碼:

<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="#4d4d4d" HorizontalOptions="FillAndExpand"> 
    <Label Text="2600 Michelson" HorizontalOptions="Center" /> 
    <RelativeLayout VerticalOptions="FillAndExpand"> 
    <ListView ItemsSource ="{Binding Meters}" HasUnevenRows="True" 
     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}" 
     RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}" > 
    ... 
    </ListView> 
    <Button Text="Green button" BackgroundColor="#299164" Opacity="0.9" 
     RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=-50}" 
     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-100}"> 
    </Button> 
    </RelativeLayout> 
    <Label Text="This label is not visible" TextColor="#0000ff"></Label> 
<StackLayout> 

下面是截圖:

enter image description here

我還遠遠沒有結束的設計,但是這是應該是這樣的:

enter image description here

+0

我不明白爲什麼您使用RelativeLayout的。 StackLayout是不夠的? –

+0

我需要有ListView和頂部的按鈕(不低於) – Uros

+0

頂部是「超過」?和「按鈕下的」按鈕?你有mokeup嗎? –

回答

4

我瘦了你可以使用網格。試試這個代碼

XAML

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="TestRelativeLayout.MyPage1" 
      Title="TabbedPage"> 
      <StackLayout VerticalOptions="FillAndExpand"> 
       <Button Clicked="Handle_Clicked" Text = "Press"> 
      </Button> 
        <Grid VerticalOptions = "FillAndExpand"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="4*" /> 
         <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="3*" /> 
         <ColumnDefinition Width="2*" /> 
         <ColumnDefinition Width="3*" /> 
        </Grid.ColumnDefinitions> 

        <ListView ItemsSource="{Binding Lista}" Grid.Row = "0" Grid.Column = "0" Grid.RowSpan = "2" Grid.ColumnSpan = "3" VerticalOptions = "FillAndExpand" HorizontalOptions="FillAndExpand"> 
         <ListView.ItemTemplate> 
         <DataTemplate> 
          <TextCell Text="{Binding .}" /> 
         </DataTemplate> 
        </ListView.ItemTemplate> 
       </ListView> 
       <Button Text = "ButtonOver" Opacity="0.5" BackgroundColor = "Fuchsia" Grid.Row="1" Grid.Column = "1"/> 

      </Grid> 
    </StackLayout> 
</ContentPage> 

這是結果

The button is "OVER"

+0

我有點懷疑,但最終它看起來像我是如何贏得的。謝謝。 – Uros

+0

你爲什麼持懷疑態度?網格是Xamarin Forms中強大的佈局之一。和RelativeLayout最好不要使用它,你可以在這篇文章中看到http://kent-boogaart.com/blog/jason-smith's-xamarin-forms-performance-tips –