【问题标题】:Xamarin.Forms ListView on specific positionXamarin.Forms ListView 在特定位置
【发布时间】:2017-09-22 03:43:23
【问题描述】:

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

【问题讨论】:

  • 问题有点混乱!您已在下拉列表或下拉列表中添加列表视图作为列表视图项目模板? “我们无法获得下拉特定位置” - 这意味着您无法获得 selectedIndex ?
  • @Dineshkumar 我们有一个 ListView,我们想将其用作 Xamarin.Forms(IOS) 的下拉列表
  • 你能分享一些你尝试过的代码吗?

标签: xaml xamarin xamarin.ios xamarin.forms


【解决方案1】:

我认为你可以使用两种方式。

第一种方法是使用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>

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

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

【讨论】:

  • 感谢您的建议,将尝试一下
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多