【发布时间】:2019-05-07 20:07:27
【问题描述】:
我通过列表视图旋转 270 度和数据模板旋转 90 度的内容视图创建动态水平列表视图,但内容视图没有展开
我尝试设置 VerticalOptions="FillAndExpand" 和 HorizontalOptions="FillAndExpand" 并尝试设置 RelativeLayout.WidthConstraint 和 RelativeLayout.HeightConstraint 但它不起作用
<RelativeLayout HeightRequest="40" BackgroundColor="Pink" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<ListView Rotation="270" x:Name="Horizonlist" ItemsSource="Hlist" RowHeight="130" SeparatorVisibility="Default" SeparatorColor="#EEEEEE" BackgroundColor="Gray"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=-15}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=-0.5, Constant=15}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant, Constant=40}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ContentView Rotation="90" BackgroundColor="Blue" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HeightRequest="200" WidthRequest="200">
<StackLayout Spacing="0" BackgroundColor="Green" Orientation="Vertical" HorizontalOptions="FillAndExpand" WidthRequest="200" HeightRequest="200">
<Label Rotation="0" Text="AAAAAAAAAAAAAA" WidthRequest="200" HeightRequest="200" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" VerticalTextAlignment="Center" TextColor="Black" BackgroundColor="Yellow"/>
</StackLayout>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</RelativeLayout>
【问题讨论】:
-
你能提供一张你想要的效果的截图吗?
-
@LucasZhang-MSFT 我已经添加了,谢谢
-
@SutineeM。我建议在数据模板中使用 Grid 而不是“ContentView 中的 StackLayout”,因为 Grid 布局可以很好地扩展。我想说添加 contentview 和 stacklayout 太复杂了。也尽量不要对标签使用硬编码的高度和宽度,而是用换行符限制它们。希望对您有所帮助。
-
@Dilmah 我尝试使用 Grid 但它不起作用
标签: xaml xamarin.forms