Android Gesture手势操作(手势翻页效果)及幻灯片放映(3)

如果想要实现幻灯片效果的话,就是自定实现图片切换。可以使用Thread ,Runable,Handler来实现之

private Handler handler;
 private Runnable runnable ;

runnable = new Runnable(){
            int i = 0;
            @Override
            public void run() {
                // TODO Auto-generated method stub
               
                //Message对象由Android系统提供
                Message msg = handler.obtainMessage();
                //将msg对象arg1成员变量设置为i;
                msg.arg1 = i;
                i++;
                try{
                    Thread.sleep(5000);
                }catch(InterruptedException e ){
                    e.printStackTrace();
                }
                handler.sendMessage(msg);
                if(i == 11){
                    i = 0;
                }
               
            }
           
           
        };
       
       
       
        handler = new Handler(){

@Override
            public void handleMessage(Message msg) {
                // TODO Auto-generated method stub
                super.handleMessage(msg);
                switch(msg.arg1){
               
                case 1:
                case 2:
                case 3:           
                case 4:
                case 5:
                case 6:   
                case 7:
                case 8:
                case 9:   
                case 10:
                    flipper.setInAnimation(AnimationUtils.loadAnimation(MainActivity.this,
                            R.drawable.left_in));
                    flipper.setOutAnimation(AnimationUtils.loadAnimation(MainActivity.this,
                            R.drawable.left_out));
                    flipper.showNext();
                    break;
                   
                }
                handler.post(runnable);
            }
           
           
        };

通过    handler.post(runnable);
                //open the state

触发

而动画效果:

left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="">
    <translate android:fromXDelta="100%p"
        android:toXDelta="0"
        android:duration="500" />
</set>

left_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="">
    <translate android:fromXDelta="0" android:toXDelta="-100%p"
        android:duration="500" />
</set>

还有其他的事件

@Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }
@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;
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxgyz.html