Android 自定义库不滚动
我谨此提问: 我试图实现我的自定义库,如下所示:Android 自定义库不滚动,android,custom-controls,xamarin.android,android-gallery,xamarin.mobile,Android,Custom Controls,Xamarin.android,Android Gallery,Xamarin.mobile,我谨此提问: 我试图实现我的自定义库,如下所示: public class CustomGallery : Gallery { public CustomGallery(Context context, IAttributeSet attrs) : base(context, attrs) { Initialize(); } public CustomGallery(Cont
public class CustomGallery : Gallery
{
public CustomGallery(Context context, IAttributeSet attrs) :
base(context, attrs)
{
Initialize();
}
public CustomGallery(Context context, IAttributeSet attrs, int defStyle) :
base(context, attrs, defStyle)
{
Initialize();
}
private void Initialize()
{
}
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
Keycode kEvent;
if (isScrollingLeft(e1, e2))
{ //Check if scrolling left
kEvent = Keycode.DpadLeft;
}
else
{ //Otherwise scrolling right
kEvent = Keycode.DpadRight;
}
OnKeyDown(kEvent, null);
return true;
}
private bool isScrollingLeft(MotionEvent e1, MotionEvent e2)
{
return e2.GetX() > e1.GetX();
}
}
我已经在我的版面中引用了自定义图库,我看到了第一幅图像,但当我尝试滚动到下一幅图像时,什么也没有发生
奇怪的是,如果我删除OnFling的覆盖,我的图库中仍然没有任何滚动?当然,如果我不重写任何内容,我的自定义组件的行为应该与普通的库组件类似吗
PS:当我向左或向右滑动时,我想一次滚动一个图像,我要做的就是阻止画廊滚动多个图像
感谢您的帮助 抓起这篇帖子,我发现,我在活动中验证了OnTouch事件>