2014-03-26 37 views
0

我在我的项目中有25张图片 我在第一个活动中有一个按钮,当点击此按钮时,我希望我的应用程序显示25的第一张图片,然后我想要在手机上轻扫左右或右右图片并更改我的照片 帮我请 它在我的Android如何更改图像刷卡?

验证码心不是重要的第一个经验:d

package com.example.start; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.LinearLayout; 
import android.view.MotionEvent; 
import android.view.GestureDetector.OnGestureListener; 
import android.view.GestureDetector; 
import android.widget.TextView; 
import android.graphics.Color; 

public class MainActivity extends Activity implements OnGestureListener 
{ 
    private LinearLayout main; 
    private TextView viewA; 
    private GestureDetector gestureScanner; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState);  
     gestureScanner = new GestureDetector(this); 

     main = new LinearLayout(this);  
     main.setBackgroundColor(Color.GRAY); 
     main.setLayoutParams(new LinearLayout.LayoutParams(320,480)); 

     viewA = new TextView(this);  
     viewA.setBackgroundColor(Color.YELLOW); 
     viewA.setTextColor(Color.BLACK); 
     viewA.setTextSize(16); 
     viewA.setLayoutParams(new LinearLayout.LayoutParams(320,80)); 

     main.addView(viewA); 
     setContentView(main); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent me) 
    { 
     return gestureScanner.onTouchEvent(me); 
    } 

    @Override 

    public boolean onDown(MotionEvent e) 
    { 
     viewA.setText("-" + "DOWN" + "-"); 
     return true; 
    } 

    @Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
    { 
     viewA.setText("-" + "FLING" + "-"); 
     return true; 
    } 

    @Override 
    public void onLongPress(MotionEvent e) 
    { 
     viewA.setText("-" + "LONG PRESS" + "-"); 
    } 

    @Override 
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) 
    { 
     viewA.setText("-" + "SCROLL" + "-"); 
     return true; 
    }  

    @Override 
    public void onShowPress(MotionEvent e) 
    { 
     viewA.setText("-" + "SHOW PRESS" + "-"); 
    }  

    @Override 
    public boolean onSingleTapUp(MotionEvent e)  
    { 
     viewA.setText("-" + "SINGLE TAP UP" + "-"); 
     return true; 
    } 

} 

回答

0

你不应该试图imlemente姿态functionnailies这样。在这里,我会告诉你使用一个ViewPager,比如图库应用程序。

有一个真正的示例here带有视频,所以你可以看到你如何从左到右滑动。

+0

你能说出更详细的答案吗? 我在哪里可以找到这个代码? – user3410344