package com.neusoft.daiyy;
import com.neusoft.daiyy.R;
import android.app.TabActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.ViewFlipper;
public class MyTab extends TabActivity implements OnTabChangeListener,
OnTouchListener, OnGestureListener {
private TabHost myTabhost;
protected int myMenuSettingTag = 0;
protected Menu myMenu;
private int tabSize = 0;
private int oldTabId = -1;
// 翻页使用
private ViewFlipper mFlipper;
GestureDetector mGestureDetector;
private static final int FLING_MIN_DISTANCE = 100;
private static final int FLING_MIN_VELOCITY = 50;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myTabhost = this.getTabHost();
// get Tabhost
LayoutInflater.from(this).inflate(R.layout.main, myTabhost.getTabContentView(), true);
myTabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));
myTabhost.addTab(myTabhost.newTabSpec("One").setIndicator("A", getResources().getDrawable(R.drawable.conf_artists)).setContent(R.id.widget_layout_Blue));
tabSize++;
myTabhost.addTab(myTabhost.newTabSpec("Two").setIndicator("B", getResources().getDrawable(R.drawable.conf_folder)).setContent(R.id.widget_layout_green));
tabSize++;
myTabhost.addTab(myTabhost.newTabSpec("Thr").setIndicator("C", getResources().getDrawable(R.drawable.conf_person)).setContent(R.id.widget_layout_red));
tabSize++;
mFlipper = (ViewFlipper) findViewById(R.id.flipper);
// 注册一个用于手势识别的类
mGestureDetector = new GestureDetector(this);
// 给mFlipper设置一个listener
mFlipper.setOnTouchListener(this);
// 允许长按住ViewFlipper,这样才能识别拖动等手势
mFlipper.setLongClickable(true);
}
public void animateChangeTab(int index) {
Animation slideLeftIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_left_in);
Animation slideLeftOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_left_out);
Animation slideRightIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_right_in);
Animation slideRightOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_right_out);
Log.v("newIndex", index + "");
Log.v("oldTabId", oldTabId + "");
// 定义退出效果
if (index > oldTabId) {
if (tabSize - 1 == index && oldTabId == 0) {
myTabhost.getCurrentView().startAnimation(slideRightOut);
} else {
myTabhost.getCurrentView().startAnimation(slideLeftOut);
}
} else if (index < oldTabId) {
if (0 == index && oldTabId == tabSize - 1) {
myTabhost.getCurrentView().startAnimation(slideLeftOut);
} else {
myTabhost.getCurrentView().startAnimation(slideRightOut);
}
}
myTabhost.setCurrentTab(index);
// 定义进入效果
int curTabId = myTabhost.getCurrentTab();
if (curTabId > oldTabId) {
if (tabSize - 1 == curTabId && oldTabId == 0) {
myTabhost.getCurrentView().startAnimation(slideRightIn);
} else {
myTabhost.getCurrentView().startAnimation(slideLeftIn);
}
} else if (curTabId < oldTabId) {
if (0 == curTabId && oldTabId == tabSize - 1) {
myTabhost.getCurrentView().startAnimation(slideLeftIn);
} else {
myTabhost.getCurrentView().startAnimation(slideRightIn);
}
}
Log.v("curTabId", curTabId + "");
Log.v("oldTabId", oldTabId + "");
this.oldTabId = myTabhost.getCurrentTab();
}
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
/**
* 用户按下触摸屏、快速移动后松开即触发这个事件 e1:第1个ACTION_DOWN MotionEvent e2:最后一个ACTION_MOVE
* MotionEvent velocityX:X轴上的移动速度,像素/秒 velocityY:Y轴上的移动速度,像素/秒 触发条件 :
* X轴的坐标位移大于FLING_MIN_DISTANCE,且移动速度大于FLING_MIN_VELOCITY个像素/秒
*/
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
myMenuSettingTag++;
while (myMenuSettingTag > tabSize - 1) {
myMenuSettingTag = myMenuSettingTag - tabSize;
}
animateChangeTab(myMenuSettingTag);
} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
myMenuSettingTag--;
while (myMenuSettingTag < 0) {
myMenuSettingTag = myMenuSettingTag + tabSize;
}
animateChangeTab(myMenuSettingTag);
}
return false;
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public boolean onTouch(View v, MotionEvent event) {
// 一定要将触屏事件交给手势识别类去处理(自己处理会很麻烦的)
return mGestureDetector.onTouchEvent(event);
}
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
}
}
TIGoss
- 粉丝: 6
- 资源: 9
最新资源
- 串联式、并联式、混联式混合动力系统simulink控制策略模型(串联式、并联式、混联式每个都是独立的需要单独说拿哪个,默认是混联式RB) 有基于逻辑门限值、状态机的规则控制策略(RB)、基于等效燃油
- 法码滋.exe法码滋2.exe法码滋3.exe
- python-geohash-0.8.5-cp38-cp38-win-amd64
- Matlab根据flac、pfc或其他软件导出的坐标及应力、位移数据再现云图 案例包括导出在flac6.0中导出位移的fish代码(也可以自己先准备软件导出的坐标数据及对应点的位移或应力数据,可根据需
- 拳皇97.exe拳皇972.exe拳皇973.exe
- 捕鱼达人1.exe捕鱼达人2.exe捕鱼达人3.exe
- 医疗骨折摄像检测29-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma数据集合集.rar
- ks滑块加密算法与源代码
- 医护人员检测23-YOLOv8数据集合集.rar
- 1.电力系统短路故障引起电压暂降 2.不对称短路故障分析 包括:共两份自编word+相应matlab模型 1.短路故障的发生频次以及不同类型短路故障严重程度,本文选取三类典型的不对称短路展开研究
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页