2017-04-14 94 views
0

我們正在使用Xamarin.From中的ListView並將其顯示爲下拉菜單,但我們無法獲得特定位置的下拉菜單,並嘗試過使用絕對佈局來實現它?Xamarin.Forms ListView在特定位置

+0

問題有點混亂!你已經添加列表視圖內下拉或下拉列表視圖itemtemplate? 「我們無法獲得特定位置」 - 這意味着您無法獲取selectedIndex? – Dilmah

+0

@Dineshkumar我們有一個ListView,我們想用它作爲Xamarin.Forms(IOS)的下拉菜單 –

+0

你可以分享一些你嘗試過的代碼嗎? – Dilmah

回答

0

我覺得你可以用兩種方法。

第一種方式是使用RelativeLayout

RelativeLayout的用於相對於同級視圖的佈局的性質或位置和大小的觀點。與AbsoluteLayout不同,RelativeLayout沒有移動錨點的概念,也沒有相對於佈局底部或右側邊緣定位元素的功能。 RelativeLayout確實支持定界元素在它自己範圍之外。

例如

<RelativeLayout> 
    <BoxView Color="Red" x:Name="redBox" 
     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, 
      Property=Height,Factor=.15,Constant=0}" 
     RelativeLayout.WidthConstraint="{ConstraintExpression 
      Type=RelativeToParent,Property=Width,Factor=1,Constant=0}" 
     RelativeLayout.HeightConstraint="{ConstraintExpression 
      Type=RelativeToParent,Property=Height,Factor=.8,Constant=0}" /> 
    <BoxView Color="Blue" 
     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, 
      ElementName=redBox,Property=Y,Factor=1,Constant=20}" 
     RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, 
      ElementName=redBox,Property=X,Factor=1,Constant=20}" 
     RelativeLayout.WidthConstraint="{ConstraintExpression 
      Type=RelativeToParent,Property=Width,Factor=.5,Constant=0}" 
     RelativeLayout.HeightConstraint="{ConstraintExpression 
      Type=RelativeToParent,Property=Height,Factor=.5,Constant=0}" /> 
</RelativeLayout> 

RelativeLayout sample

的另一種方式是使用一個網格。如果必須在Entry附近添加一個ListView(例如),可以將Entry和ListView添加到另一個下的兩個「行」中,並使用Grid.Span設置ListView的高度。我不知道這個效果很好......但你可以試試。否則,在Grid的單元格內添加一個RelativeLayout,然後將你的Entry和ListView添加到這個RelativeLayout。

你有一些現在要做的練習;)

+0

感謝您的建議,將嘗試一下 –