的onClick阻塞onFling [英] onClick blocking onFling
问题描述
在我的活动我有一个ImageView的(顶部)和TextView的(底部)。使用这两种观点我显示图像和其相应的描述。我一直在使用'SimpleOnGestureListener'..,这样用户可以通过不同的图像和其相应的描述一扔(每次一扔,我加载不同的图像,并将其展示给用户)来实现一扔。
In my activity I have an imageView(at the top) and textView(at the bottom). Using both views I display an image and its corresponding description. I have implemented fling using 'SimpleOnGestureListener'..so that user can fling through different images and its corresponding description(on every fling, I load different image and show it to user).
现在的问题开始时,我加入onClickListener的ImageView的(我需要检测的onClick,这样我可以显示图像的描述敬酒)。但onClick的似乎是阻塞一扔事件。如何检测一扔。
Now the problem started when I added onClickListener for the ImageView( I need to detect onClick so that I can display a Toast with description of the image). But the onClick seems to be blocking the fling event. How do I detect fling.
通过本论坛下面的问题(和其他几个)已走了。
Have already gone through the following questions(and few others) in this forum..
<一个href=\"http://stackoverflow.com/questions/6664756/android-giving-ontouch-priority-over-onclick\">android - 给onTouch优先的onClick
但还是没能找出解决办法。
but still could not identify the solution.
下面给出的是code
Given below is the code
public class MainActivity extends Activity{
ImageView m_imageView;
String[] m_imageNames = { "img1__", "img2__", "img2__"};
int m_index = 0;
Resources m_res;
Drawable m_drawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("INFO", "Inside oncreate");
m_imageView = (ImageView)findViewById(R.id.imageView1);
m_res = getResources();
int imageId = m_res.getIdentifier(m_imageNames[m_index], "drawable", getPackageName());
Drawable drawable = m_res.getDrawable(imageId);
m_imageView.setImageDrawable(drawable);
m_imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.v("INFO", "Inside onClick");
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.v("INFO", "onTouchEvent detected");
return gestureDetector.onTouchEvent(event);
}
SimpleOnGestureListener simpleOnGestureListener
= new SimpleOnGestureListener(){
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
//Fling code goes here
}
};
GestureDetector gestureDetector = new GestureDetector(null, SimpleOnGestureListener);
}
推荐答案
这些方法一般有布尔
回报,这表明,该事件已经被消耗掉,不应继续传播。尝试改变返回值。
These methods generally have boolean
returns, which indicate that this event has been consumed and should not propagate further. Try changing return values.
这篇关于的onClick阻塞onFling的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!