android单个页面切换_Android 中利用ViewFlipper 滑动屏幕切换页面,ListView展示数据...

package com.hll.ViewFlipperTest;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.os.Bundle;

import android.view.GestureDetector;

import android.view.GestureDetector.OnDoubleTapListener;

import android.view.GestureDetector.OnGestureListener;

import android.view.MotionEvent;

import android.view.View;

import android.view.View.OnTouchListener;

import android.view.animation.AccelerateInterpolator;

import android.view.animation.Animation;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

import android.widget.ViewFlipper;

@SuppressLint("NewApi")public classViewFlipperTest extends Activity implements OnTouchListener,

OnGestureListener, OnDoubleTapListener {private ViewFlipper mFlipper; //翻转视图

GestureDetector mGestureDetector; //手势识别

private int mCurrentLayoutState; //当前布局状态

private static final int FLING_MIN_DISTANCE = 2;private static final int FLING_MIN_VELOCITY = 200;

TextView counttv;

Button buttonNext1= null;

Button buttonNext2= null;

ListView lv1= null;

@Overridepublic voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

findView();

setListener();

}/** 查找控件*/@SuppressWarnings("deprecation")public voidfindView() {

mFlipper=(ViewFlipper) findViewById(R.id.details);

mFlipper.setLongClickable(true);

mGestureDetector= new GestureDetector(this);

mCurrentLayoutState= 0;

counttv=(TextView) findViewById(R.id.counttv);

buttonNext1=(Button) findViewById(R.id.Button_next1);

buttonNext2=(Button) findViewById(R.id.Button_next2);

lv1=(ListView) findViewById(R.id.list1);

lv1.setAdapter(new HgroupAdapter(this, null, 0));

}public voidsetListener() {

mFlipper.setOnTouchListener(this);

lv1.setOnTouchListener(this);

counttv.setText("9");

buttonNext1.setOnClickListener(newView.OnClickListener() {public voidonClick(View view) {

mFlipper.showNext();

counttv.setText("7");

}

});

buttonNext2.setOnClickListener(newView.OnClickListener() {public voidonClick(View view) {

mFlipper.showNext();

counttv.setText("8");

}

});

}// protectedAnimation inFromRightAnimation() {

Animation inFromRight= newTranslateAnimation(

Animation.RELATIVE_TO_PARENT,+1f,

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,0.0f);

inFromRight.setDuration(300);

inFromRight.setInterpolator(newAccelerateInterpolator());returninFromRight;

}protectedAnimation outToLeftAnimation() {

Animation outtoLeft= newTranslateAnimation(

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,-1f,

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,0.0f);

outtoLeft.setDuration(300);

outtoLeft.setInterpolator(newAccelerateInterpolator());returnouttoLeft;

}protectedAnimation inFromLeftAnimation() {

Animation inFromLeft= newTranslateAnimation(

Animation.RELATIVE_TO_PARENT,-1.0f,

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,0.0f);

inFromLeft.setDuration(300);

inFromLeft.setInterpolator(newAccelerateInterpolator());returninFromLeft;

}protectedAnimation outToRightAnimation() {

Animation outtoRight= newTranslateAnimation(

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,+1.0f,

Animation.RELATIVE_TO_PARENT,0.0f,

Animation.RELATIVE_TO_PARENT,0.0f);

outtoRight.setDuration(300);

outtoRight.setInterpolator(newAccelerateInterpolator());returnouttoRight;

}publicboolean onDown(MotionEvent e) {//TODO Auto-generated method stub

return false;

}public boolean onFling(MotionEvent e1, MotionEvent e2, floatvelocityX,floatvelocityY) {if (e1.getX() - e2.getX() >FLING_MIN_DISTANCE&& Math.abs(velocityX) >FLING_MIN_VELOCITY) {

mFlipper.setInAnimation(inFromRightAnimation());

mFlipper.setOutAnimation(outToLeftAnimation());

mFlipper.showNext();

}else if (e2.getX() - e1.getX() >FLING_MIN_DISTANCE&& Math.abs(velocityX) >FLING_MIN_VELOCITY) {

mFlipper.setInAnimation(inFromLeftAnimation());

mFlipper.setOutAnimation(outToRightAnimation());

mFlipper.showPrevious();

}return false;

}public voidonLongPress(MotionEvent e) {//TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "onLongPress", Toast.LENGTH_LONG)

.show();

}public boolean onScroll(MotionEvent e1, MotionEvent e2, floatdistanceX,floatdistanceY) {

Toast.makeText(getApplicationContext(),"onScroll", Toast.LENGTH_LONG)

.show();return false;

}public voidonShowPress(MotionEvent e) {//TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "onShowPress", Toast.LENGTH_LONG)

.show();

}publicboolean onSingleTapUp(MotionEvent e) {//TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "onSingleTapUp", Toast.LENGTH_LONG)

.show();return false;

}public boolean onTouch(View v, MotionEvent event) {return mGestureDetector.onTouchEvent(event);

}publicboolean onDoubleTap(MotionEvent e) {//TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "onDoubleTap", Toast.LENGTH_LONG)

.show();return false;

}publicboolean onDoubleTapEvent(MotionEvent e) {//TODO Auto-generated method stub

return false;

}publicboolean onSingleTapConfirmed(MotionEvent e) {//TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "onSingleTapConfirmed", Toast.LENGTH_LONG)

.show();return false;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值