首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CollectionView中水平填充项目,每个项目在xamarin表单中采用屏幕宽度

在CollectionView中水平填充项目,每个项目在xamarin表单中采用屏幕宽度
EN

Stack Overflow用户
提问于 2021-01-03 02:26:50
回答 1查看 72关注 0票数 0

我尝试将CollectionView中的项目水平放置在一行中,因为每个项目都应该填满屏幕宽度。然而,在当前的设置中,它不会填充屏幕的宽度。我正在寻找的是在水平方向上一次一个项目。

代码语言:javascript
复制
<DataTemplate x:Key="UpdateRecentItemTemplate">
            <ContentView BackgroundColor="Yellow" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <yummy:PancakeView Style="{StaticResource Pancake}" VerticalOptions="Center" HeightRequest="80" BackgroundGradientStartPoint="0,0" BackgroundGradientEndPoint="0,1">
                    <yummy:PancakeView.Shadow>
                        <yummy:DropShadow Color="{Binding BindingContext.FirstColor, Source={x:Reference MyPage}}" BlurRadius="1"></yummy:DropShadow>
                    </yummy:PancakeView.Shadow>
                    <yummy:PancakeView.BackgroundGradientStops>
                        <yummy:GradientStopCollection>
                            <yummy:GradientStop Color="{Binding BindingContext.FirstColor, Source={x:Reference MyPage}}" Offset="0" />
                            <yummy:GradientStop Color="{Binding BindingContext.SecondColor, Source={x:Reference MyPage}}" Offset="1" />
                        </yummy:GradientStopCollection>
                    </yummy:PancakeView.BackgroundGradientStops>
                    <StackLayout VerticalOptions="Center" BackgroundColor="Transparent">
                        <Label Grid.Row="0">
                            <Label.FormattedText>
                                <FormattedString>
                                    <Span Text="{Binding ChapterID, StringFormat=' {0} '}" FontSize="Small"/>
                                    <Span Text="{Binding ArabicEnglishName, StringFormat=' {0} '}" FontSize="Medium" FontAttributes="Bold"/>
                                </FormattedString>
                            </Label.FormattedText>
                        </Label>
                        <Label Grid.Row="1">
                            <Label.FormattedText>
                                <FormattedString>
                                    <Span Text="{Binding AyaNumber, StringFormat=' Ayat No. {0}'}" FontSize="Medium"/>
                                </FormattedString>
                            </Label.FormattedText>
                        </Label>
                    </StackLayout>
</yummy:PancakeView>
            </ContentView>

[![<Grid HeightRequest="140" Padding="0" BackgroundColor="Red">
                                    <CollectionView ItemsSource="{Binding Recents}"
                                                    VerticalScrollBarVisibility="Never" HorizontalScrollBarVisibility="Never" HorizontalOptions="FillAndExpand"
                                            ItemTemplate="{StaticResource UpdateRecentItemTemplate}" x:Name="RecentView">
                                        <CollectionView.ItemsLayout>
                                            <GridItemsLayout Orientation="Horizontal"  HorizontalItemSpacing="5" Span="1" />
                                        </CollectionView.ItemsLayout>
                                    </CollectionView>
                                </Grid>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-04 05:41:01

最简单的方法是使用Carouselview而不是CollectionView。使用Carouselview,我们可以设法一次水平显示一个项目。所以用Carouselview更改了CollectionView,并且它起作用了。此外,我一次只有4个项目要展示,所以在这种情况下,Carouselview比CollectionView更接近。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65542615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档