2016-10-16 40 views
0

我想向我的頁面添加一個浮動動作按鈕,爲此我用相對佈局包裝了我的堆棧佈局,並在相對佈局中添加了FABStackLayout在RelativeLayout裏面是不可見的

<ContentPage.Content> 
    <RelativeLayout BackgroundColor="Transparent"> 
     <fab:FloatingActionButton 
       x:Name="fabBtn" 
       Source="plus.png" 
       Size="Normal" 
       Clicked="Handle_FabClicked" 
       NormalColor="Green" 
     RippleColor="Blue" 
       RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-75}" 
       RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-75}" /> 
     <StackLayout 
     Spacing="10" 
     Padding="5" 
     VerticalOptions="FillAndExpand" 
     HorizontalOptions="FillAndExpand" 
     RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
       RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"> 
     <Label Text="Latest news/activities" FontSize="Medium" VerticalOptions="Start"/> 
     <ScrollView VerticalOptions="CenterAndExpand"> 
      <ListView 
      x:Name="lsvActivities" 
      HasUnevenRows="True"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
       <ViewCell> 
        <StackLayout Orientation="Horizontal" Padding="3"> 
        <StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand"> 
         <Label Text="{Binding title}" VerticalOptions="StartAndExpand"/> 
         <Label Text="{Binding date}" VerticalOptions="End"/> 
        </StackLayout> 
        <StackLayout HorizontalOptions="End" WidthRequest="100" HeightRequest="100" BackgroundColor="Blue"> 
         <Label Text="image here"/> 
        </StackLayout> 
        </StackLayout> 
       </ViewCell> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
      </ListView> 
     </ScrollView> 
     <Label Text="Good Mording" FontSize="Large" VerticalOptions="End" HorizontalOptions="Center"/> 
     </StackLayout> 
    </RelativeLayout> 
    </ContentPage.Content> 

但它鎖定就像StackLayout超出了佈局的邊界或其他東西。

enter image description here

是什麼問題呢?以及如何顯示FAB和StackLayout,其中浮動操作按鈕應始終位於StackLayout元素的頂部

+1

可以去掉滾動型? ListView已經在滾動。 –

回答

3

您是否試圖讓StackLayout佔據整個屏幕(頂部有按鈕)?如果是這樣,這部分是不會做的:

RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"> 

即放置StackLayout的左上角屏幕的右下角。

Xamarin docs

不同於AbsoluteLayout,RelativeLayout的不具有 移動錨定件的概念,並且不具有用於定位元件 相對於底部或佈局的右邊緣設施。

換句話說,如果您將某些東西放在右下角,AbsoluteLayout將嘗試爲您調整。 RelativeLayout不會。

你可能想在StackLayout上面提到的是WidthConstraint和HeightConstraint,以及XConstraint和YConstraint設置爲0

而作爲斯文 - 邁克爾說,下降了滾動的約束。

編輯

的XAML應該看起來像:

RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}" 
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant,Constant=0}" 
RelativeLayout.YConstraint="{ConstraintExpression Type=Constant,Constant=0}" 
+0

你能告訴我這兩條線會是怎樣的嗎?我試圖讓'因子= 0',但現在stackLayout的高度沒有擴大;我想stacklayout的高度儘可能最大[imgur.com/a/W5GVW](http://imgur.com/a/W5GVW) –

+0

首先,試試這個:RelativeLayout.WidthConstraint =「{ConstraintExpression Type = RelativeToParent ,Property = Width,Factor = 1}「 RelativeLayout.HeightConstraint =」{ConstraintExpression Type = RelativeToParent,Property = Height,Factor = 1}「 – DavidS

+0

這也沒有效果[imgur.com/3gzcMXF](http: imgur.com/3gzcMXF) –

相關問題