Xaml Xamarin.在特定位置上形成ListView

Xaml Xamarin.在特定位置上形成ListView,xaml,xamarin,xamarin.ios,xamarin.forms,Xaml,Xamarin,Xamarin.ios,Xamarin.forms,我们正在使用Xamarin中的ListView。从中,我们将其显示为下拉列表,但我们无法获得下拉列表的特定位置,我们尝试了绝对布局来实现它?我认为您可以使用两种方式 第一种方法是使用 RelativeLayout用于相对于布局或同级视图的属性定位和调整视图大小。与AbsoluteLayout不同,RelativeLayout没有移动锚的概念,也没有相对于布局的底部或右边缘定位元素的设施。RelativeLayout支持将元素定位在其自身边界之外 比如说 <RelativeLayout>

我们正在使用Xamarin中的ListView。从中,我们将其显示为下拉列表,但我们无法获得下拉列表的特定位置,我们尝试了绝对布局来实现它?

我认为您可以使用两种方式

第一种方法是使用

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>

另一种方法是使用网格。如果必须在条目附近添加ListView(例如),可以在两行中添加条目和ListView,一行在另一行下,并使用Grid.Span设置ListView的高度。我不知道这很有效。。。但是你可以试试。否则,在网格单元格中添加RelativeLayout,然后将条目和ListView添加到此RelativeLayout


你现在有一些练习要做;)

这个问题有点让人困惑!您在下拉列表中添加了listview还是将下拉列表作为listview项目模板?“我们无法获取下拉列表的特定位置”-这意味着您无法获取selectedIndex?@Dineshkumar我们有一个列表视图,我们想将其用作Xamarin的下拉列表。表单(IOS)您可以分享一些您尝试过的代码吗?感谢您的建议,我们将尝试它