【问题标题】:Contentview within horizontal listview not expanded水平列表视图中的内容视图未展开
【发布时间】:2019-05-07 20:07:27
【问题描述】:

我通过列表视图旋转 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>

预期布局

【问题讨论】:

  • 你能提供一张你想要的效果的截图吗?
  • @LucasZhang-MSFT 我已经添加了,谢谢
  • @SutineeM。我建议在数据模板中使用 Grid 而不是“ContentView 中的 StackLayout”,因为 Grid 布局可以很好地扩展。我想说添加 contentview 和 stacklayout 太复杂了。也尽量不要对标签使用硬编码的高度和宽度,而是用换行符限制它们。希望对您有所帮助。
  • @Dilmah 我尝试使用 Grid 但它不起作用

标签: xaml xamarin.forms


【解决方案1】:
   <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>

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

【讨论】:

  • 为什么滚动视图不滚动?
  • Scrollview 不滚动,因为我在 relativelayout 中设置了 srollview,所以我刚刚删除了 relativelayout,它现在可以工作了。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 2016-10-29
  • 1970-01-01
相关资源
最近更新 更多