首页 > 解决方案 > 水平列表视图中的内容视图未展开

问题描述

我通过列表视图旋转 270 度和数据模板旋转 90 度的内容视图创建动态水平列表视图,但内容视图没有扩展

我尝试设置 VerticalOptions="FillAndExpand" 和 Horizo​​ntalOptions="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>

预期布局 预期布局

标签: xamlxamarin.forms

解决方案


   <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>

为了实现类似输出的水平列表视图,您可以使用上述代码中所示的可绑定布局


推荐阅读