水平列表视图中的ContentView未展开

时间:2019-05-07 03:36:04

标签: xaml xamarin.forms

我通过270度的列表视图旋转和90度的datatemplate旋转来动态创建地平线列表视图,但是contentview不会扩展

我尝试设置VerticalOptions =“ FillAndExpand”和Horizo​​ntalOptions =“ FillAndExpand”,还尝试设置RelativeLayout.WidthConstraint和RelativeLayout.HeightConstraint,但是它不起作用

that's i got

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

预期的布局 Expected layout

1 个答案:

答案 0 :(得分:0)

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

在oreder中获得像输出一样的水平列表视图,您可以使用上面代码中所示的可绑定布局