Android的 - 手势检测(刷卡向上/向下)的特定视图 [英] Android - Gesture Detection (Swipe up/down) on particular view
本文介绍了Android的 - 手势检测(刷卡向上/向下)的特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现在Android上OnGestureListener。
我有三个TextViews在我的布局。
什么,我想实现的是设置手势侦听器两个textViews的。
这是在布局 -
I am trying to implement the OnGestureListener in Android.
I have three TextViews in my layout.
What i am trying to achieve is to set Gesture Listener for two of the textViews .
Here is the layout -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="One" />
<TextView
android:id="@+id/tvTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvOne"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Two" />
<TextView
android:id="@+id/tvThree"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTwo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Three" />
这里是在活动 -
And here is the activity -
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
public class TimeActivity extends Activity implements OnGestureListener {
GestureDetector gestureScanner;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wheelview);
gestureScanner = new GestureDetector(this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return gestureScanner.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
Log.i("Test", "On Fling");
return true;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
在present一扔了所有三个textviews获取调用。
有没有什么办法,通过它我可以设置在手势监听器在布局一些特定的观点。
任何帮助将是非常美联社preciated。
At present Fling for all the three textviews is getting called .
Is there any way through which i can set the Gesture Listener for some particular views in the layout.
Any help will be highly appreciated.
推荐答案
在的onCreate
办法做到这一点。
findViewById(R.id.tvOne).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event){
return gestureScanner.onTouchEvent(event);
}
});
这篇关于Android的 - 手势检测(刷卡向上/向下)的特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文