Android屏幕切换效果实现
屏幕切换效果实现
摘自:程云峰,网名 icess,杭州恒生电子研发中心。
个人网站: http://www.chengyunfeng.com/
通过查看 OPhone API文档可以发现,有个android.widget.ViewAnimator类继承至FrameLayout,ViewAnimator类的作用是为FrameLayout里面的View切换提供动画效果。该类有如下几个和动画相关的函数:
- setOutAnimation: 设置View退出屏幕时候使用的动画,参数setInAnimation函数一样。
- showNext: 调用该函数来显示FrameLayout里面的下一个View。
- showPrevious: 调用该函数来显示FrameLayout里面的上一个View。
- isFlipping: 用来判断View切换是否正在进行
- setFilpInterval:设置View之间切换的时间间隔
- startFlipping:使用上面设置的时间间隔来开始切换所有的View,切换会循环进行
- stopFlipping: 停止View切换
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <ViewFlipper android:id="@+id/details"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:persistentDrawingCache="animation"
- android:flipInterval="1000"
- android:inAnimation="@anim/push_left_in"
- android:outAnimation="@anim/push_left_out"
- >
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="Next"
- android:id="@+id/Button_next1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <ImageView
- android:id="@+id/image1"
- android:src="@drawable/dell1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ImageView>
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="Next"
- android:id="@+id/Button_next2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <ImageView
- android:id="@+id/image2"
- android:src="@drawable/lg"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ImageView>
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="Next"
- android:id="@+id/Button_next3"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <ImageView
- android:id="@+id/image3"
- android:src="@drawable/lenovo"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ImageView>
- </LinearLayout>
- </ViewFlipper>
- </LinearLayout>
- res/anim/push_left_in.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:fromXDelta="100%p"
- android:toXDelta="0"
- android:duration="500"/>
- <alpha
- android:fromAlpha="0.0"
- android:toAlpha="1.0"
- android:duration="500" />
- </set>
- res/anim/push_left_out.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:fromXDelta="0"
- android:toXDelta="-100%p"
- android:duration="500"/>
- <alpha
- android:fromAlpha="1.0"
- android:toAlpha="0.0"
- android:duration="500" />
- </set>
- public class TestActivity extends Activity {
- private ViewFlipper mViewFlipper;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button buttonNext1 = (Button) findViewById(R.id.Button_next1);
- mViewFlipper = (ViewFlipper) findViewById(R.id.flipper);
- buttonNext1.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- //在layout中定义的属性,也可以在代码中指定
- // mViewFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in);
- // mViewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out);
- // mViewFlipper.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
- // mViewFlipper.setFlipInterval(1000);
- mViewFlipper.showNext();
- //调用下面的函数将会循环显示mViewFlipper内的所有View。
- // mViewFlipper.startFlipping();
- }
- });
- Button buttonNext2 = (Button) findViewById(R.id.Button_next2);
- buttonNext2.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- mViewFlipper.showNext();
- }
- });
- Button buttonNext3 = (Button) findViewById(R.id.Button_next3);
- buttonNext3.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- mViewFlipper.showNext();
- }
- });
- }
- }
- class TestActivity extends Activity implements OnGestureListener , OnDoubleTapListener
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
- float velocityY) {
- Log.d(tag, "...onFling...");
- if(e1.getX() > e2.getX()) {//move to left
- mViewFlipper.showNext();
- }else if(e1.getX() < e2.getX()) {
- mViewFlipper.setInAnimation(getApplicationContext(), R.anim.push_right_in);
- mViewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_right_out);
- mViewFlipper.showPrevious();
- mViewFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in);
- mViewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out);
- }else {
- return false;
- }
- return true;
- }
- public boolean onDoubleTap(MotionEvent e) {
- Log.d(tag, "...onDoubleTap...");
- if(mViewFlipper.isFlipping()) {
- mViewFlipper.stopFlipping();
- }else {
- mViewFlipper.startFlipping();
- }
- return true;
- }
- public GestureDetector(OnGestureListener listener) {
- this(null, listener, null);
- }
- public GestureDetector(Context context, OnGestureListener listener, Handler handler) {
- if (handler != null) {
- mHandler = new GestureHandler(handler);
- } else {
- mHandler = new GestureHandler();
- }
- mListener = listener;
- if (listener instanceof OnDoubleTapListener) {
- setOnDoubleTapListener((OnDoubleTapListener) listener);
- }
- init(context);
Android屏幕切换效果实现相关推荐
- Android 屏幕切换效果实现 (转)
本教程将介绍如何实现屏幕间的切换效果.在前述 Ophone 2D UI 动画教程 中介绍了OPhone提供的animation功能,里面介绍了如何操作具体View的动画效果,在一般情况下我们希望在程序 ...
- MTk屏幕切换效果的制作
http://blog.csdn.net/menghnhhuan/article/details/6025019 学习MTK三四个月了,总要写点东西出来才行,这里简单说说,怎么制作屏幕切换效果.一些基 ...
- (转)MTk屏幕切换效果的制作
学习MTK三四个月了,总要写点东西出来才行,这里简单说说,怎么制作屏幕切换效果.一些基本的概念,我就不说了,图层的原理和对图层操作的一些函数,至少要了解. 进入主题,说一下我的思路:首先,在进入新屏幕 ...
- android 屏幕切换监听
昨天,我试着在屏幕切换时,使View显示在不同的位置,在网上搜索了一些资料,自己做了一段时间,终于完成了功能. 由于屏幕切换会调用activity的各个生命周期,所以需要在manifest的activ ...
- android实时监控屏幕代码,Android 屏幕切换监听的实例代码
昨天,我试着在屏幕切换时,使View显示在不同的位置,在网上搜索了一些资料,自己做了一段时间,终于完成了功能. 由于屏幕切换会调用activity的各个生命周期,所以需要在manifest的activ ...
- 【转】 Android 屏幕切换总结
转自 http://www.open-open.com/lib/view/open1328069449468.html Android横竖屏要解决的问题应该就两个: 一.布局问题 二.重新载入问题 1 ...
- Android屏幕切换
点击"银行"进入"易惠通 - 银行"屏: GridView屏对应MainActivity:ListView屏对应BankActivity. 这两个Activ ...
- Android实现程序前后台切换效果
本文演示如何在Android中实现程序前后台切换效果. 在介绍程序实现之前,我们先看下Android中Activities和Task的基础知识. 我们都知道,一个Activity 可以启动另一个Act ...
- Android的Activity屏幕切换动画(一)-左右滑动切换
为什么80%的码农都做不了架构师?>>> 这段时间一直在忙Android的项目,总算抽出点时间休息一下,准备把一些项目用到的Android经验分享一下. 在Android开发过 ...
最新文章
- C++中图像处理的类之二 CImg
- JDK8新特性LocalDate、LocalTime和LocalDateTime
- Linux下MySQL基础使用命令
- POP3启用LDAP实现自动加载邮件通讯录的过程
- win11虚拟机如何安装 Windows11虚拟机安装步骤教程
- 365RSS.cn = Web3.0?
- 计算机五笔教案ppt,计算机应用基础课件(五笔字型课件).ppt
- wwwscan/wscan 简单使用
- Python面向对象加强2.Python 中类的内置属性和内置方法(魔法函数)
- CVPR2021 最具创造力的那些工作成果!或许这就是计算机视觉的魅力!
- 激流之傲服务器维修,国服3月15日部分服务器预计维护16小时
- Tenth season eleventh episode,Ross is Monica‘s first kiss?????the stripper cried?????
- PDA库存盘点,有效提高电子制造企业库存盘点效率
- 2017ACM-ICPC亚洲区域赛(西安站)
- 自媒体都有什么平台,哪些平台好?
- MacOS / Vmware Fusion无法连接虚拟设备sata0:1,因为主机上没有相应设备
- VLAN的概念及配置
- 一款可同时对接饿了么、美团、饿百零售的小票打印机
- theano学习--theano.tensor
- D - The Beatles CodeForces - 1143D