android는 좌우로 미끄러지는 제스처를 이용하여 avtivity의 점프를 실현한다
                                            
 10879 단어  android 학습
                    
package com.goushispwsz.mobilesafewsz;
import com.guoshispwsz.mobilesafewsz.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.Toast;
public class Setup1Activity extends Activity implements OnTouchListener, OnGestureListener{
    GestureDetector mGestureDetector;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //             
        setContentView(R.layout.setup1);
        mGestureDetector = new GestureDetector(this,this);
        //mGestureDetector = new GestureDetector((OnGestureListener) this);
        LinearLayout Setup1ActivityLayout = (LinearLayout)findViewById(R.id.setup1);     
        Setup1ActivityLayout.setOnTouchListener(this);     
        Setup1ActivityLayout.setLongClickable(true);  
    }
    /**
     *                    -           ,
     *     Button      android:onClick=next,
     * @param view
     */
    public void next(View view){
        Intent intent = new Intent(this,Setup2Activity.class);
        startActivity(intent);
        finish();
        //Activity       。               ,        startActivity(intent)  finish()        。
        //   :           ,    :          。
        overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
    }
    @Override
    public boolean onDown(MotionEvent e) {
        // TODO          
        return false;
    }
    @Override
    public void onShowPress(MotionEvent e) {
        // TODO          
    }
    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO          
        return false;
    }
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        // TODO          
        return false;
    }
    @Override
    public void onLongPress(MotionEvent e) {
        // TODO          
    }
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO          
         if (e1.getX()-e2.getX() > 50   
                    && Math.abs(velocityX) > 0) {   
             Intent intent = new Intent(this,Setup2Activity.class);
            startActivity(intent);
            finish();
                Toast.makeText(this, "    ", Toast.LENGTH_SHORT).show();   
            } else if (e2.getX()-e1.getX() > 50   
                    && Math.abs(velocityX) > 0) {   
          Toast.makeText(this, "    ", Toast.LENGTH_SHORT).show();   
            }   
            return false; 
    }
        //*************
        /*float minMove = 120;         //      
        float minVelocity = 0;      //      
        float beginX = e1.getX();     
        float endX = e2.getX();
        float beginY = e1.getY();     
        float endY = e2.getY();
        if(beginX-endX>minMove&&Math.abs(velocityX)>minVelocity){   //  
            Toast.makeText(this,velocityX+"  ",Toast.LENGTH_SHORT).show();
        }else if(endX-beginX>minMove&&Math.abs(velocityX)>minVelocity){   //  
            Intent intent = new Intent(this,Setup2Activity.class);
            startActivity(intent);
            finish();
            Toast.makeText(this,velocityX+"  ",Toast.LENGTH_SHORT).show();
        }else if(beginY-endY>minMove&&Math.abs(velocityY)>minVelocity){   //  
            Toast.makeText(this,velocityX+"  ",Toast.LENGTH_SHORT).show();
        }else if(endY-beginY>minMove&&Math.abs(velocityY)>minVelocity){   //  
            Toast.makeText(this,velocityX+"  ",Toast.LENGTH_SHORT).show();
        }
        return false;
    }*/
/*  public class SnsConstant {   
        private static final int FLING_MIN_DISTANCE = 50;     
        private static final int FLING_MIN_VELOCITY = 0;   
        public static int getFlingMinDistance() {   
            return FLING_MIN_DISTANCE;   
        }   
        public  int getFlingMinVelocity() {   
            return FLING_MIN_VELOCITY;   
        }   
    }  */
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO          
        return mGestureDetector.onTouchEvent(event); 
        //return false;
    }
}
  1. 두 가지를 물려받아야 한다implements OnTouchListener, OnGestureListener 2.GestureDetector mGestureDetector를 실례화하려면 다음과 같이 하십시오.3. oncreate에 적는다
mGestureDetector = new GestureDetector(this,this);
        //mGestureDetector = new GestureDetector((OnGestureListener) this);
        LinearLayout Setup1ActivityLayout = (LinearLayout)findViewById(R.id.setup1);     
        Setup1ActivityLayout.setOnTouchListener(this);     
        Setup1ActivityLayout.setLongClickable(true);  4.다시 쓰기
 
 @Override 
 public boolean onTouch(View v, MotionEvent event) { 
 // TODO           
 return mGestureDetector.onTouchEvent(event); 
 //return false; 
 }5.인터넷에서 코드 방법을 찾았어요. onfling.@Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO          
         if (e1.getX()-e2.getX() > 50   
                    && Math.abs(velocityX) > 0) {   
             Intent intent = new Intent(this,Setup2Activity.class);
            startActivity(intent);
            finish();
                Toast.makeText(this, "    ", Toast.LENGTH_SHORT).show();   
            } else if (e2.getX()-e1.getX() > 50   
                    && Math.abs(velocityX) > 0) {   
          Toast.makeText(this, "    ", Toast.LENGTH_SHORT).show();   
            }   
            return false; 
    }  //일부 내용은 인터넷에서 골라 개인 필기용으로만 한다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
kernel 버전 번호 수정kernel 버전 번호 수정 방법은 다음과 같습니다. 파일을 수정하려면 다음과 같이 하십시오. 구체적으로 다음과 같이 수정되었습니다. kernel/fs/proc/version.c linux_proc_banner 는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.