我的项目中有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;
}
}