如何使用gesture呢,如何判断手势。向上或先下运动呢,,最后有个案例,,让我分析一下,学习学习。。我弄不明白什么是gesture,这个如何使用。。

解决方案 »

  1.   

    http://blog.csdn.net/xiaominghimi/article/details/6130196
      

  2.   

    我要实现两个组件。都要监听gesture吗。。那么如何判断这两个,触摸屏幕的时候那个是那个呢,,
      

  3.   

    假设垂直有三个组件A B C, 组件B在中间,我向上拖动B 时,,B移到了A组件的位置。C移到了B组件的位置。A移到了组件C的位置,,是一个循环。。有没有这样类似的例子呢,,不过谢谢你的回答啊,,
      

  4.   

    sdk的samples下有个示例程序GestureBuilder
    楼主可以直接用这个程序绘制gesture,生成的手势库文件在SCDard上,默认文件名称为:gestures
    接下来在应用中加载手势库文件,然后开发手势识别代码。
    把手势库文件gestures文件拷贝到你的项目的res/raw目录下。以下是我写的手势识别代码,楼主可以参考下
    package com.litian.gesture;import java.util.List;import android.app.Activity;
    import android.gesture.Gesture;
    import android.gesture.GestureLibraries;
    import android.gesture.GestureLibrary;
    import android.gesture.GestureOverlayView;
    import android.gesture.GestureOverlayView.OnGestureListener;
    import android.gesture.GestureOverlayView.OnGesturePerformedListener;
    import android.gesture.Prediction;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.Toast;public class MainActivity extends Activity {

    private static final String TAG = "MainActivity";
    private GestureOverlayView overlayView;
    private GestureLibrary library;
    private Gesture gesture;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            //1.得到手势库(raw文件夹下的gestures文件)
            library = GestureLibraries.fromRawResource(this, R.raw.gestures);
       
            //2.加载手势库
            library.load();
            
            //3.获取绘图区域GestureOverlayView
            overlayView = (GestureOverlayView)this.findViewById(R.id.gestures);
            
            //4.为View添加手势监听事件
            //只针对单笔绘制事件
            //overlayView.addOnGesturePerformedListener(new MyGesturePerformedListener());
            
            //针对多笔绘制事件
            overlayView.addOnGestureListener(new MyOnGestureListener());
        }
        
        //处理按钮响应事件
        public void find(View v){
         if(gesture != null){
         recognize(gesture);
         }
        
         overlayView.clear(true);
        }
        
        //手势识别
        private void recognize(Gesture gesture) {
        
         //从手势库中查询匹配的内容,匹配的结果可能包括多个相似的内容,匹配度高的结果放在最前面
            List<Prediction> predictions = library.recognize(gesture); //predictions:预言,预言的事物
            
            //开始判断匹配的结果
            if(!predictions.isEmpty()){
             Prediction prediction = predictions.get(0); //取第一个值(即最匹配的值)
             if(prediction.score >= 6){
             if("x".equals(prediction.name)){
                 //画XX
                 Toast.makeText(this, R.string.x, Toast.LENGTH_SHORT).show();
                 }else if("o".equals(prediction.name)){
                 //画O
                 Toast.makeText(this, R.string.x, Toast.LENGTH_SHORT).show();
                 }else if("cock".equals(prediction.name)){
                 //画小鸡鸡
                 Toast.makeText(this, R.string.cock, Toast.LENGTH_SHORT).show();
                 }else if("five".equals(prediction.name)){
                 //画五角星
                 Toast.makeText(this, R.string.five, Toast.LENGTH_SHORT).show();
                 }else if("ok".equals(prediction.name)){
                 //画勾
                 Toast.makeText(this, R.string.ok, Toast.LENGTH_SHORT).show();
                 }else if("three".equals(prediction.name)){
                 //画三角形
                 Toast.makeText(this, R.string.three, Toast.LENGTH_SHORT).show();
                 }else if("li".equals(prediction.name)){
                 //写“李”字
                 Toast.makeText(this, R.string.li, Toast.LENGTH_SHORT).show();
                 }else if("tian".equals(prediction.name)){
                 //写“田”字
                 Toast.makeText(this, R.string.tian, Toast.LENGTH_SHORT).show();
                 }
             }else{
             //匹配度过低
             Toast.makeText(this, R.string.low, Toast.LENGTH_SHORT).show();
             }
            }else{
             //匹配度过低
             Toast.makeText(this, R.string.not_find, Toast.LENGTH_SHORT).show();
            }
    } //自定义手势监听事件内部类(多笔绘制)
        private class MyOnGestureListener implements OnGestureListener{ @Override
    public void onGestureStarted(GestureOverlayView overlay,
    MotionEvent event) {
    //Log.i(TAG, "onGestureStarted()");
    } @Override
    public void onGesture(GestureOverlayView overlay, MotionEvent event) {
    //Log.i(TAG, "onGesture()");
    } @Override
    public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {
    //Log.i(TAG, "onGestureEnded()");
    //监听手势结束事件
    gesture = overlay.getGesture();
    } @Override
    public void onGestureCancelled(GestureOverlayView overlay,
    MotionEvent event) {
    //Log.i(TAG, "onGestureCancelled()");
    }
        }
        
        //Gesture执行完成监听器(单笔绘制)
        private class MyGesturePerformedListener implements OnGesturePerformedListener{     //Gesture执行完成事件
    @Override
    public void onGesturePerformed(GestureOverlayView overlay,
    Gesture gesture) {
    //Log.i(TAG, "onGesturePerformed()");

    //监听此事件,gesture由系统传入
    recognize(gesture);
    }
        
        }    //销毁时做一些必要的处理
    @Override
    protected void onDestroy() {
    super.onDestroy();
    //myPid的解释:Returns the identifier of this process, 
    //which can be used with killProcess and sendSignal.
    android.os.Process.killProcess(android.os.Process.myPid());
    }
        
        
    }~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    另外,布局文件为:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <android.gesture.GestureOverlayView
        android:layout_width="fill_parent" 
        android:layout_height="0dip" 
        android:layout_weight="1"
        android:gestureStrokeType="multiple"
        android:id="@+id/gestures"
        />
        <Button
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/btn_label"
    android:onClick="find"
        />
    </LinearLayout>
      

  5.   

    http://android.tgbus.com/Android/tutorial/201108/362438.shtml和这个很像只不过是上下滚动。。
      

  6.   

    这个滚动的效果我已经实现了,,现在又有问题了,,怎么让ImageView.变淡呢,,而不是变透明,,我想让当前显示的变亮,其余的变暗,大家知道有什么方法吗???