Android ViewFlipper滑动屏幕切换图片【安卓进化十九】
最近看到ViewFlipper和Animation在一起的用法,感觉很好,我就自己写了一下,感觉灰常好用,效果比gallery的滚动查看图片好用多了,这个也是实现滚动屏幕切换图片,但是用户体验要好很多!所以我把自己写的demo分享一下!希望对大家有用,也方便我自己以后查阅!转载请标明出处:
http://blog.csdn.net/wdaming1986/article/details/6766058
程序一开始界面,第一张图片: 向右滑动屏幕切换到第二张图片:
向右滑动切换第三张图片:
向左滑动就又切换到第二张图片了!
以此类推!
代码奉上:
一、MainActivity。java类文件:
package com.cn.daming;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
public class MainActivity extends Activity implements OnGestureListener{
private GestureDetector detector;
private ViewFlipper flipper;
private final int HELPFILP_RESULT = 106;
Intent getMainActivity = null;
int count = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawBackground();
LayoutInflater inflater = LayoutInflater.from(this);
final View layout = inflater.inflate(R.layout.view_flipper, null);
setContentView(layout);
flipper = (ViewFlipper) findViewById(R.id.view_flipper);
detector = new GestureDetector(this);
}
public void drawBackground()
{
GradientDrawable grad = new GradientDrawable(
Orientation.TL_BR,
new int[] {Color.rgb(0, 0, 127),
Color.rgb(0, 0, 255),
Color.rgb(127, 0, 255),
Color.rgb(127, 127, 255),
Color.rgb(127, 255, 255),
Color.rgb(255, 255, 255)}
);
this.getWindow().setBackgroundDrawable(grad);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated metho
补充:移动开发 , Android ,