我的申请书里有一张照片库。如果我选择一张照片,所选的照片将显示在另一个页面上,并带有左右箭头。点击左边箭头时,相册的前一张图片在屏幕上是可见的,如果点击右箭头,相册中的下一张图片将出现在屏幕上。
截图

我需要查看下/先前的图片,而不点击箭头。可以通过左右滑动来查看图片吗?是否有任何控制来识别右/左屏幕滑动?
发布于 2019-08-08 11:22:56
CarouselView来找你了!!

技术注意:在您在CollectionView和AppDelegate中初始化Xamarin.Forms之前,使用一个特性标志启用Xamarin.Forms(这也启用了MainActivity.cs ):
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");如果不想使用新特性,可以添加SwipeGestureRecognizer
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/swipe
为了快速加载和缓存图像,我使用这个库
发布于 2019-08-08 16:01:39
但是要小心,因为CarouselView在预览中,您不应该在生产应用程序中使用它。
因此,在没有发布CollectionView之前,您可以使用这个:
https://github.com/roubachof/Sharpnado.Presentation.Forms#carousel-layout

发布于 2019-08-09 03:00:41
我需要查看下/先前的图片,而不点击箭头。可以通过左右滑动来查看图片吗?是否有任何控制来识别右/左屏幕滑动?
如果您想这样做,我建议您可以使用CarouselViewControl。您需要通过nuget安装CarouseView.FormsPlugin。你可以点击箭头,或者向右滑动来查看图片。
然后添加此引用
<ContentPage
x:Class="Demo1.listviewcontrol.Page3"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:cv="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions">
<ContentPage.Content>
<Grid>
<cv:CarouselViewControl
x:Name="carousel"
AnimateTransition="True"
ItemsSource="{Binding MyItemsSource}"
Orientation="Horizontal"
PositionSelected="Handle_PositionSelected"
PositionSelectedCommand="{Binding MyCommand}"
Scrolled="Handle_Scrolled"
ShowArrows="true"
ShowIndicators="true" />
</Grid>
</ContentPage.Content>
public partial class Page3 : ContentPage
{
public Page3 ()
{
InitializeComponent ();
this.BindingContext = new MainViewModel();
}
private void Handle_PositionSelected(object sender, CarouselView.FormsPlugin.Abstractions.PositionSelectedEventArgs e)
{
Debug.WriteLine("Position " + e.NewValue + " selected.");
}
private void Handle_Scrolled(object sender, CarouselView.FormsPlugin.Abstractions.ScrolledEventArgs e)
{
Debug.WriteLine("Scrolled to " + e.NewValue + " percent.");
Debug.WriteLine("Direction = " + e.Direction);
}
}
public class MainViewModel
{
public ObservableCollection<View> _myItemsSource;
public ObservableCollection<View> MyItemsSource
{
set
{
_myItemsSource = value;
}
get
{
return _myItemsSource;
}
}
public Command MyCommand { protected set; get; }
public MainViewModel()
{
MyItemsSource = new ObservableCollection<View>()
{
new CachedImage() { Source = "a1.jpg", DownsampleToViewSize = true, Aspect = Aspect.AspectFill },
new CachedImage() { Source = "c2.jpg", DownsampleToViewSize = true, Aspect = Aspect.AspectFill },
new CachedImage() { Source = "c3.jpg", DownsampleToViewSize = true, Aspect = Aspect.AspectFill }
};
MyCommand = new Command(() =>
{
Debug.WriteLine("Position selected.");
});
}
}我使用CacheImage,所以通过nuget安装Xamarin.FFimageLoading.Forms。
请在主活动OnCreate方法中添加以下代码
CarouselViewRenderer.Init();
CachedImageRenderer.Init(true);

https://stackoverflow.com/questions/57411292
复制相似问题