• [Android1.5]Android2.0版本以下Activity切换动画效果



    前言

      在Android 2.0版本以上做Activity切换时的动画效果是很容易的,可以调用overridePendingTransition函数,一行代码搞定,当然配置动画效果的xml文件是少不了的,但是在2.0版本以下是没有这个函数的,如何方便的做动画效果呢?有说用ViewFlipper或者getWindow().setWindowAnimations,但是这里都没有成功,用了一个取巧的办法,但是效果还不错:)

    声明

      欢迎转载,但请保留文章原始出处:)

        博客园:http://www.cnblogs.com

        农民伯伯: http://www.cnblogs.com/over140/

    正文

      一、流程说明

        点击Activity1中按钮btnLogin切换到Activity2,切换要求有缩放的动画效果。

      二、实现原理

        在Activity2加载时启用顶层容器的动画效果,注意顶层容器最好是整屏。

      三、实现代码

        Activity1.java

        /**
         * 登录
         
    */
        @Override
        
    public void onClick(View view) {
            startActivity(getIntent().setClass(
    this, Activity2.class));
        }

        Activity2.java

        @Override
        
    public void onCreate(Bundle savedInstanceState) {
            
    super.onCreate(savedInstanceState);
            setContentView(R.layout.test2);
            Animation anim = AnimationUtils.loadAnimation(this,R.anim.my_scale_action);
            findViewById(R.id.body).startAnimation(anim);


        }

        test2.xml

    <LinearLayout android:id="@+id/body"
        xmlns:android
    ="http://schemas.android.com/apk/res/android"
        android:layout_width
    ="fill_parent" android:layout_height="fill_parent"
        android:orientation
    ="vertical" >

            
    <TextView android:layout_x="179dp" android:layout_y="78dp"
                android:id
    ="@+id/test"
                android:layout_width
    ="wrap_content" android:layout_height="wrap_content"
                android:textColor
    ="#c5dde7" android:textStyle="bold">
            
    </TextView>
    </LinearLayout>

        my_scale_action.xml 动画效果的配置文件

    <set xmlns:android="http://schemas.android.com/apk/res/android">
        
    <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:fromXScale
    ="0.0" 
            android:toXScale
    ="1.0" 
            android:fromYScale
    ="0.0"
            android:toYScale
    ="1.0" 
            android:pivotX
    ="50%" 
            android:pivotY
    ="50%"
            android:fillAfter
    ="true" 
            android:duration
    ="300" />
    </set>

          代码说明:

            a)  注意代码Activity2.java加粗标红的两行代码,是本文的核心。

            b)  R.id.body为顶层容器的id

            c)  关于缩放的xml文件大家可以搜索一下,有相关的中文资料,搜索关键字:"android 动画效果"。

    结束

       由图片的动画效果联想到View的动画效果再联想到用顶层View做动画效果,效果还不错,仍然在低版本奋斗的朋友有福了:)

  • 相关阅读:
    洛谷P1352没有上司的舞会+树形二维DP
    高精度模板(从洛谷题解中骗来的
    Codeforces#398 &767C. Garland 树形求子节点的和
    LuoGu-P1122 最大子树和+树形dp入门
    HDU-3549Flow Problem 最大流模板题
    Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类
    Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
    数据结构&字符串:01字典树
    数据结构:可持久化平衡树
    数据结构:并查集-拆点
  • 原文地址:https://www.cnblogs.com/over140/p/1867003.html
Copyright © 2020-2023  润新知