如何解决如何在CollectionView中制作方形图像
请帮忙。我尝试制作方形图像,但我做不到,也不明白为什么(
<CollectionView ItemsSource="{Binding Types}"
SelectionMode="None">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal" HorizontalItemSpacing="10"
/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.RowDeFinitions>
<RowDeFinition Height="150" />
</Grid.RowDeFinitions>
<Grid.ColumnDeFinitions>
<ColumnDeFinition Width="150" />
</Grid.ColumnDeFinitions>
<Image Source="{Binding Image}"/>
<Label Text="eiffel" TextColor="Red" FontFamily="Roboto" HorizontalOptions="Start" VerticalOptions="End" FontAttributes="Bold"></Label>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
我想要的
我有什么
请帮助我使它们变方形
解决方法
您需要设置图像的外观:
<Image Source="{Binding Image}" Aspect="AspectFill"/>
,
您可以使用FFImageLoading来做到这一点。将以下NuGet软件包添加到解决方案中的每个项目中。
Xamarin.FFImageLoading
Xamarin.FFImageLoading.Forms
Xamarin.FFImageLoading.Transformations (if you’ll use transformations like CircleTransformation)
将WidthRequest
和HeightRequest
设置为相同的值。
使用以下代码来实现它
<ffimageloading:CachedImage HorizontalOptions="Center" VerticalOptions="Center"
WidthRequest="200" HeightRequest="200"
DownsampleToViewSize="true"
Source = "test2.jpg">
<ffimageloading:CachedImage.Transformations>
<fftransformations:CornersTransformation CornersTransformType="AllRounded" BottomLeftCornerSize="8" BottomRightCornerSize="8" TopLeftCornerSize="8" TopRightCornerSize="8"/>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
我的测试图像:
这是代码运行结果
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。