Xaml 水平listview中的Contentview未展开
我通过listview旋转270度和contentview在datatemplate旋转90度来动态创建水平listview,但contentview没有展开 我试过设置VerticalOptions=“FillAndExpand”和HorizontalOptions=“FillAndExpand”,也试过设置RelativeLayout.WidthConstraint和RelativeLayout.HeightConstraint,但都不起作用Xaml 水平listview中的Contentview未展开,xaml,xamarin.forms,Xaml,Xamarin.forms,我通过listview旋转270度和contentview在datatemplate旋转90度来动态创建水平listview,但contentview没有展开 我试过设置VerticalOptions=“FillAndExpand”和HorizontalOptions=“FillAndExpand”,也试过设置RelativeLayout.WidthConstraint和RelativeLayout.HeightConstraint,但都不起作用 预期布局 为了实现类似水平listvi
预期布局
为了实现类似水平listview的输出,您可以使用上述代码中所示的可绑定布局您可以提供一个关于所需效果的屏幕截图吗?@LucasZhang MSFT我已经添加了,thanks@SutineeM. 我建议在datatemplate中使用Grid而不是“ContentView中的StackLayout”,因为Grid布局可以很好地扩展。我认为添加contentview和stacklayout太复杂了。另外,不要对标签使用硬编码的高度和宽度,而应使用换行符限制它们。希望有帮助。@Dilmah我尝试使用网格,但它不起作用为什么scrollview不滚动?scrollview不滚动,因为我在relativelayout中设置了srollview,所以我刚刚删除了relativelayout,现在可以了。非常感谢。
<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>
<ScrollView Orientation="Horizontal"> <StackLayout Orientation="Horizontal" BindableLayout.ItemsSource="{Binding carousel_list}" IsVisible="{Binding carousel_visibility}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal">
<Image Source="{Binding image}" VerticalOptions="Start" WidthRequest="300"/>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>