问题描述
在我的 Xamarin 应用程序中,我有一个 CardView
,它基本上是一个 Frame
,在那里我有一个 ListView
,里面有 StackPanels
和 Grids
样式如下图所示:
我已经准备好了,除了黄线。将该行添加到 CardView
的最佳和最简单的方法是什么?
最初我希望向其中添加一个非重复的背景图像,就像您在 HTML/CSS 中所做的那样。但这在 CardView
中似乎是不可能的。
或者可能定位一个Image
元素绝对并将其定位到顶部/中心?我不知道该怎么做。
谁能指出我正确的方向?
解决方法
您可以使用 RelativeLayout 和 BoxView 来实现这一点:
例如:
<RelativeLayout>
<Frame CornerRadius="20" x:Name="cardview" WidthRequest="300">
<Label Text="$11.95"
TextColor="Black"
FontSize="11"
FontAttributes="Bold"
HorizontalOptions="Start"/>
</Frame>
<BoxView HeightRequest="2" BackgroundColor="Yellow" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView,ElementName=cardview,Property=Width,Factor=0.5,Constant=-50}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView,Property=Height,Factor=0}"
WidthRequest="100"
/>
</RelativeLayout>