在 android 左右滑动图像视图

Swipe imageview left and right in android

我在屏幕中央有 Imageview。

我想左右滑动 Imageview screen.How 我可以实现吗?

看看https://github.com/nadavfima/GlowPadView

它有 glowpadview 的开源实现。

您可以将其用作参考并根据需要更改图标。它应该创建可滑动的视图。

我也在寻找一些非常简单的解决方案。我只需要 left/right 轻扫。我发现了许多过于复杂的解决方案。所以我尽可能地减少了我发现的东西,并想出了一些非常简单的东西(在这个例子中,滑动将在具有 ID mainarea 的 div 上工作,检测到向任一侧至少 100px 的滑动):

var swipe={
 startx:0,touch:function(event) {
 if (typeof event.touches!=='undefined') {
   switch (event.type) {
    case 'touchstart':swipe.startx=event.touches[0].pageX;
    case 'touchend':
     if(Math.abs(swipe.startx-event.changedTouches[0].pageX)>100)
      swipe.startx<event.changedTouches[0].pageX?window.location.href=swipe.prev:window.location.href=swipe.next
   }
  }
 },init:function(prev,next){
  swipe.prev=prev;
  swipe.next=next;
  document.getElementById("mainarea").addEventListener('touchstart',swipe.touch,false);
  document.getElementById("mainarea").addEventListener('touchend',swipe.touch,false);
 }
}
swipe.init(<previous page>,<next page>);