java自定义表格渲染器,列表视图和项目选择/点击的自定义渲染器

我正在开发一个xamarin表单项目中用于android的自定义渲染器左右滑动 . 我有一个类实现方法“DispatchTouchEvent(MotionEvent touch)”的重写 . 当引发MotionEventActions.Up时,我会做一些事情 . 我在ListView的共享代码中实现了一个“ItemSelected”事件,但是当我在listview的一个元素上滑动时,它会解释这是一个tap,这会触发这个事件 .

当我点击或滑动元素时,如何区分?

当我在“MotionEventActions.Up”中滑动时,我一直在考虑不同,但我不知道如何从自定义渲染器显示新页面 .

这是渲染器的代码:

class SwipeListRenderer : ListViewRenderer

{

bool swipe = false;

bool scroll;

double puntoYinicial = 0.0;

public override bool DispatchTouchEvent(MotionEvent touch)

{

try

{

if (puntoYinicial == 0.0)

puntoYinicial = touch.GetY();

double currentQuota = ((touch.GetX() - TouchDispatcher.StartingBiasX) / (double)this.Width);

float x = touch.GetX();

float y = touch.GetY();

SwipeList.SwipeItemView touchedElement = (TouchDispatcher.TouchingView as SwipeList.SwipeItemView);

switch (touch.ActionMasked)

{

case MotionEventActions.Down:

(this.Element as SwipeList.SwipeListView).RestoreItemPosition();

swipe = false;

scroll = false;

return base.DispatchTouchEvent(touch);

break;

case MotionEventActions.Up:

if (swipe)

touchedElement.CompleteTranslation(currentQuota);

(this.Element as SwipeList.SwipeListView).AppendTouchedElement(touchedElement);

TouchDispatcher.TouchingView = null;

TouchDispatcher.StartingBiasX = 0;

TouchDispatcher.StartingBiasY = 0;

puntoYinicial = 0.0;

break;

case MotionEventActions.Move:

if (touchedElement != null)

TouchDispatcher.TouchingView.PerformTranslation(currentQuota);

break;

}

return base.DispatchTouchEvent(touch);

}

catch (Exception ex)

{

throw;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值