package com.wind.gesturetabhost;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TabHost;
import android.widget.ViewFlipper;
public class WindGestureTabHostActivity extends TabActivity {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
/*private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private ViewFlipper viewFlipper; */
int currentView = 0;
private static int maxTabIndex = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("sun ",getResources().getDrawable(android.R.drawable.btn_star))
.setContent(new Intent(this, Activity1.class)));
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_right_out);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("wind ",getResources().getDrawable(android.R.drawable.btn_star))
.setContent(new Intent(this, Activity2.class)));
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_right_out);
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("snow ",getResources().getDrawable(android.R.drawable.btn_star))
.setContent(new Intent(this, Activity3.class)));
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_right_out);
tabHost.setCurrentTab(0);
/*slideLeftIn = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left );
slideLeftOut = AnimationUtils .loadAnimation(this, android.R.anim.slide_in_left);
slideRightIn = AnimationUtils .loadAnimation(this, android.R.anim.slide_out_right);
slideRightOut = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); */
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
}
/*private TabHost getTabHost() {
// TODO Auto-generated method stub
return null;
}*/
class MyGestureDetector extends SimpleOnGestureListener {
//@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
TabHost tabHost = getTabHost();
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.i("test ", "right");
if (currentView == maxTabIndex) {
currentView = 0;
} else {
currentView++;
}
tabHost.setCurrentTab(currentView);
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.i("test ", "left");
if (currentView == 0) {
currentView = maxTabIndex;
} else {
currentView--;
}
tabHost.setCurrentTab(currentView);
}
} catch (Exception e) {
// nothing
}
return false;
}
}
// @Override
// public boolean onTouchEvent(MotionEvent event) {
// if (gestureDetector.onTouchEvent(event))
// return true;
// else
// return false;
// }
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if(gestureDetector.onTouchEvent(event)){
event.setAction(MotionEvent.ACTION_CANCEL);
}
return super.dispatchTouchEvent(event);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
WindGestureTabHost.rar (73个子文件)
WindGestureTabHost
bin
classes.dex 7KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
wind10.png 8KB
wind12.png 6KB
wind13.png 5KB
ic_launcher.png 2KB
wind14.png 5KB
wind06.png 5KB
wind11.png 5KB
wind15.png 5KB
wind02.png 8KB
wind08.png 5KB
wind09.png 4KB
wind04.png 9KB
wind07.png 4KB
wind03.png 6KB
wind05.png 7KB
wind01.png 6KB
classes
com
wind
gesturetabhost
R$layout.class 496B
Activity2.class 518B
Activity3.class 518B
R$id.class 440B
R$drawable.class 872B
WindGestureTabHostActivity.class 3KB
Activity1.class 518B
WindGestureTabHostActivity$MyGestureDetector.class 2KB
R$attr.class 355B
WindGestureTabHostActivity$1.class 1KB
R.class 617B
R$string.class 442B
R$anim.class 561B
resources.ap_ 106KB
WindGestureTabHost.apk 113KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 202B
drawable-mdpi
wind10.png 11KB
wind12.png 9KB
wind13.png 7KB
ic_launcher.png 3KB
wind14.png 8KB
wind06.png 8KB
wind11.png 8KB
wind15.png 8KB
wind02.png 11KB
wind08.png 7KB
wind09.png 7KB
wind04.png 11KB
wind07.png 7KB
wind03.png 9KB
wind05.png 9KB
wind01.png 9KB
anim
slide_right_out.xml 249B
tranrotate.xml 579B
slide_left_out.xml 243B
slide_right_in.xml 296B
slide_left_in.xml 185B
layout
main3.xml 550B
main2.xml 550B
main1.xml 549B
main.xml 627B
assets
gen
com
wind
gesturetabhost
R.java 2KB
proguard.cfg 1KB
.settings
org.eclipse.jdt.core.prefs 208B
src
com
wind
gesturetabhost
Activity1.java 284B
Activity2.java 282B
Activity3.java 284B
WindGestureTabHostActivity.java 4KB
.project 854B
.classpath 364B
project.properties 360B
AndroidManifest.xml 932B
共 73 条
- 1
touchsnow
- 粉丝: 1542
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页