永利皇宫402卡通学习笔记

永利皇宫402 26
永利皇宫402

Bootstrap 图标由 Glyphicons 提供。详细的情况能够去bootstrap官方网址进行查看。

壹、属性动画

使用 ObjectAnimator 的时候,有好几要命重大,那正是决定的品质要享有
get,set 方法,不然ObjectAnimator
就无法起效。上面这一个事一些常用的,能够直接选择性质动画的属性值。translationX
,translationY,scaleX,ScaleY,pivotX,pivotY,x,y,阿尔法。

永利皇宫402 1

唯独,有些属性是绝非 get set 方法的,那么难道大家就不能够用了呢?不是的。

private static class WrapperView{
    private View mTarget;

    public WrapperView(View target){
        mTarget = target;
    }

    public getWidth(){
        return mTarget.getLayoutParams().width;
    }

    public void setWidth(int width){
        mTarget.getLayoutParams().width = width;
        mTarget.requestLayput();
    }
}

// 通过以上代码给属性包了一层,并给它提供了 get set 的方法。使用如下:

WrapperView wrapper = new WrapperView(mButton);
ObjectAnimator.ofInt(wrapper,"width",500).setDuration(5000).start();

看似的,借使想完成视图动画中的AnimationSet,在质量动画中能够使用
PropertyValuesHolder 来达成。

PropertyValuesHolder pvh1 = PropertyValuesHolder.ofFloat("translationX",300f);
PropertyValuesHolder pvh2 = PropertyValuesHolder.ofFloat("scaleX",1f, 0, 1f);
PropertyValuesHolder pvh3 = PropertyValuesHolder.ofFloat("scaleY",1f, 0, 1f);
PropertyValuesHolder pvh1 = PropertyValuesHolder.ofFloat("translationX",1f, 0, 1f);
ObjectAnimator.ofPropertyValuesHolder(view, pvh1, pvh2, pvh3).setDuration(1000).start();

实例:

只呈现 activity
中的代码。点击之后,自个儿变淡,四个趋势上弹出多少个Logo。再点击壹遍,收回多个Logo。

永利皇宫402 2永利皇宫402 3

public class PropertyTest extends Activity implements View.OnClickListener {

    private int[] mRes = {R.id.imageView_a, R.id.imageView_b, R.id.imageView_c,
            R.id.imageView_d, R.id.imageView_e};
    private List<ImageView> mImageViews = new ArrayList<ImageView>();
    private boolean mFlag = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.property);
        for (int i = 0; i < mRes.length; i++) {
            ImageView imageView = (ImageView) findViewById(mRes[i]);
            imageView.setOnClickListener(this);
            mImageViews.add(imageView);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageView_a:
                if (mFlag) {
                    startAnim();
                } else {
                    closeAnim();
                }
                break;
            default:
                Toast.makeText(PropertyTest.this, "" + v.getId(),
                        Toast.LENGTH_SHORT).show();
                break;
        }
    }

    private void closeAnim() {
        ObjectAnimator animator0 = ObjectAnimator.ofFloat(mImageViews.get(0),
                "alpha", 0.5F, 1F);
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(mImageViews.get(1),
                "translationY", 200F, 0);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(mImageViews.get(2),
                "translationX", 200F, 0);
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(mImageViews.get(3),
                "translationY", -200F, 0);
        ObjectAnimator animator4 = ObjectAnimator.ofFloat(mImageViews.get(4),
                "translationX", -200F, 0);
        AnimatorSet set = new AnimatorSet();
        set.setDuration(500);
        set.setInterpolator(new BounceInterpolator());
        set.playTogether(animator0, animator1, animator2, animator3, animator4);
        set.start();
        mFlag = true;
    }

    private void startAnim() {
        ObjectAnimator animator0 = ObjectAnimator.ofFloat(
                mImageViews.get(0),
                "alpha",
                1F,
                0.5F);
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(
                mImageViews.get(1),
                "translationY",
                200F);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(
                mImageViews.get(2),
                "translationX",
                200F);
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(
                mImageViews.get(3),
                "translationY",
                -200F);
        ObjectAnimator animator4 = ObjectAnimator.ofFloat(
                mImageViews.get(4),
                "translationX",
                -200F);
        AnimatorSet set = new AnimatorSet();
        set.setDuration(500);
        set.setInterpolator(new BounceInterpolator());
        set.playTogether(
                animator0,
                animator1,
                animator2,
                animator3,
                animator4);
        set.start();
        mFlag = false;
    }
}

View Code

 

用法:

2、视图动画

视图动画重要有八种,平移,旋转,缩放,反射率两种更动。视图动画要制止相互,可是其成效高,使用方便。上边看3个实际的实例:

xml 文件

永利皇宫402 4永利皇宫402 5

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Alpha"
        android:layout_margin="10dp"
        android:onClick="btnAlpha" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rotate"
        android:layout_margin="10dp"
        android:onClick="btnRotate" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rotate_self"
        android:layout_margin="10dp"
        android:onClick="btnRotateSelf" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Translate"
        android:layout_margin="10dp"
        android:onClick="btnTranslate" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Scale"
        android:layout_margin="10dp"
        android:onClick="btnScale" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Scale_Self"
        android:layout_margin="10dp"
        android:onClick="btnScaleSelf" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Anim Set"
        android:layout_margin="10dp"
        android:onClick="btnSet" />

</LinearLayout>

View Code

设置了 伍 个按钮,种种按键都安装了点击的章程。

activity 中的代码:注意点击方法传入的是 View,那样就能够一向管理啊。

永利皇宫402 6永利皇宫402 7

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void btnAlpha(View view) {
        AlphaAnimation aa = new AlphaAnimation(0, 1);
        aa.setDuration(1000);
        view.startAnimation(aa);
    }

    public void btnRotate(View view) {
        RotateAnimation ra = new RotateAnimation(0, 360, 100, 100);
        ra.setDuration(1000);
        view.startAnimation(ra);
    }

    public void btnRotateSelf(View view) {
        RotateAnimation ra = new RotateAnimation(0, 360,
                RotateAnimation.RELATIVE_TO_SELF, 0.5F,
                RotateAnimation.RELATIVE_TO_SELF, 0.5F);
        ra.setDuration(1000);
        view.startAnimation(ra);
    }

    public void btnTranslate(View view) {
        TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 300);
        ta.setDuration(1000);
        view.startAnimation(ta);
    }

    public void btnScale(View view) {
        ScaleAnimation sa = new ScaleAnimation(0, 2, 0, 2);
        sa.setDuration(1000);
        view.startAnimation(sa);
    }

    public void btnScaleSelf(View view) {
        ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1,
                Animation.RELATIVE_TO_SELF, 0.5F,
                Animation.RELATIVE_TO_SELF, 0.5F);
        sa.setDuration(1000);
        view.startAnimation(sa);
    }

    public void btnSet(View view) {
        AnimationSet as = new AnimationSet(true);
        as.setDuration(1000);

        AlphaAnimation aa = new AlphaAnimation(0, 1);
        aa.setDuration(1000);
        as.addAnimation(aa);

        TranslateAnimation ta = new TranslateAnimation(0, 100, 0, 200);
        ta.setDuration(1000);
        as.addAnimation(ta);

        view.startAnimation(as);
    }

}

View Code

 

 <i ></i>   

3、ValueAnimator

ValueAnimator
自身不提供任何动画效果,它更像多个数值发生器,用来产生负有一定规律的数字,从而让调用者来调控动画的兑现。

一个完好的动画片具备start, repeat, end, cancel 七个经过,通过Android
提供了接口,能够很方便的监听那五个事件,代码如下所示。

ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 0.5f);
anim .addListener(new AnimatorListener(){
    @Override
    public void onAnimationStart(Animator animation){}
    @Override
    public void onAnimationRepeat(Animator animation){}
    @Override
    public void onAnimationEnd(Animator animation){}
    @Override
    public void onAnimationCancel(Animator animation){}

});
anim.start();

本来大多数时候,大家都只关切 onAnimationEnd 事件,所以 Android
也提供了3个 AnimatorListenerAdapter
来让大家挑选必要的必需的事务进行监听,代码如下所示:

anim.addListener(new AnimatorListenerAdapter() {
    public void onAnimationEnd(Animator animation) {
        // TODO
    }
});

实例:

点击之后,会弹出一个下拉
item,再点击贰遍就流失。首要就是通过 ValueAnimator
 达成的。通过中间数值的扭转,来安装其入骨的转移,达到动画的机能。大家监听动画甘休的时候,然后就设置让该
item 看不见。

永利皇宫402 8永利皇宫402 9

package com.imooc.anim;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

public class DropTest extends Activity {

    private LinearLayout mHiddenView;
    private float mDensity;
    private int mHiddenViewMeasuredHeight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drop);
        mHiddenView = (LinearLayout) findViewById(R.id.hidden_view);
        // 获取像素密度
        mDensity = getResources().getDisplayMetrics().density;
        // 获取布局的高度
        mHiddenViewMeasuredHeight = (int) (mDensity * 40 + 0.5);
    }

    public void llClick(View view) {
        if (mHiddenView.getVisibility() == View.GONE) {
            // 打开动画
            animateOpen(mHiddenView);
        } else {
            // 关闭动画
            animateClose(mHiddenView);
        }
    }

    private void animateOpen(final View view) {
        view.setVisibility(View.VISIBLE);
        ValueAnimator animator = createDropAnimator(
                view,
                0,
                mHiddenViewMeasuredHeight);
        animator.start();
    }

    private void animateClose(final View view) {
        int origHeight = view.getHeight();
        ValueAnimator animator = createDropAnimator(view, origHeight, 0);
        animator.addListener(new AnimatorListenerAdapter() {
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();
    }

    private ValueAnimator createDropAnimator(
            final View view, int start, int end) {
        ValueAnimator animator = ValueAnimator.ofInt(start, end);
        animator.addUpdateListener(
                new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int value = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams =
                        view.getLayoutParams();
                layoutParams.height = value;
                view.setLayoutParams(layoutParams);
            }
        });
        return animator;
    }
}

View Code

另2个实例,机械漏刻,将数值的变通映未来分界面上。

public class TimerTest extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.timer);
    }

    public void tvTimer(final View view) {
        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 100);
        valueAnimator.addUpdateListener(
                new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                ((TextView) view).setText("$ " +
                        (Integer) animation.getAnimatedValue());
            }
        });
        valueAnimator.setDuration(3000);
        valueAnimator.start();
    }
}

 实例:3个搜索表单

4、AnimatorSet

该属性能够正确的调控的爆发的顺序。别的格局还有:animSet.play().with(),
playSequentially(), playTogether(), before(), after()。

ObjectAnimator pvh1 = ObjectAnimator.ofFloat(view, "translationX",300f);
ObjectAnimator pvh2 = ObjectAnimator.ofFloat(view, "scaleX",1f, 0, 1f);
ObjectAnimator pvh3 = ObjectAnimator.ofFloat(view, "scaleY",1f, 0, 1f);
AnimatorSet set = new AnimatorSet();
set.setDuration(1000);
set.playTogether(pvh1, pvh2, pvh3);
set.start();

永利皇宫402 10永利皇宫402 11

5、使用 XML 

叁个是性质动画的XML,另一个是帧动画。

帧动画是各种播放一组预先定义好的图片,类似于电影播放。差别于
视图动画,系统提供了另一个类 AnimationDrawable
来使用帧动画。帧动画比较简单,首先要求通过 XML 来定义一个AnimationDrawable,如下所示。

文本地方:res/drawable/frame_test.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/ic_launcher" android:duration="500"></item>
    <item android:drawable="@drawable/s1" android:duration="500"></item>
    <item android:drawable="@drawable/s2" android:duration="500"></item>
</animation-list>

接下来将上述的 Drawable 作为 View 的背景并经过 Drawable 来播放动画就可以:

Button btn = (Button) findViewById(R.id.shen);
btn.setBackgroundResource(R.drawable.frame_test);
AnimationDrawable drawable = (AnimationDrawable) btn.getBackground();
drawable.start();

帧动画相比轻易,不过轻松滋生 OOM (内存不足) ,
所以在使用帧动画的时候,尽量防止使用过多尺寸很大的图片。

<!DOCTYPE html>  <html lang="en">    <head>      <meta charset="utf-8">      <title>Example of using icons in search form - Bootstrap version 2.0</title>      <meta name="viewport" content="width=device-width, initial-scale=1.0">      <meta name="description" content="Example of using icons in search form - Bootstrap version 2.0 from w3cschool.cc">      <meta name="author" content="">        <!-- Le styles -->      <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet">      <style type="text/css">      form {      margin-top: 50px;      }      </style>      <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->      <!--[if lt IE 9]>        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>      <![endif]-->        <!-- Le fav and touch icons -->      <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico">      <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png">      <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png">      <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png">    </head>    <body>      <div class="container">        <div class="row">          <div class="span12">          <form class="well form-search">                <input type="text" class="input-medium search-query">                <button type="submit" class="btn"><i class="icon-search"></i> Search</button>          </form>          </div>          </div>          <footer>          <p>&copy; Company 2013</p>        </footer>      </div>  </body>  </html>

6、自定义动画

开创自定义动画特别轻便,只须求贯彻它的 applyTransformation
的逻辑就可以啊。然而,平时状态下,还必要覆盖父类的 initialize
方法来贯彻部分起先化工作。

applyTransformation( float interpolatedTime, Transformation t)

applyTransformation 有多少个参数,第三个是插值器的轩然大波因子,取值范围 0-一。

其次个参数是矩阵的封装类,一般选取那一个类来取安妥前的矩阵对象。通过改造获得矩阵对象来将动画实现出来。

五个实例:2个是电视关闭的卡通片,三个是自定义的3D自定义动画效果。

在 3D 自定义动画效果中,大家采纳了一个 camera,该类是
android.graphics.Camera中的 camera 类,它包裹了 openGL 的 3D
动画,从而能够很便利的创制 3D 动画功效。

永利皇宫402 12永利皇宫402 13

 1 public class CustomAnim extends Animation {
 2 
 3     private int mCenterWidth;
 4     private int mCenterHeight;
 5     private Camera mCamera = new Camera();
 6     private float mRotateY = 0.0f;
 7 
 8     @Override
 9     public void initialize(int width,
10                            int height,
11                            int parentWidth,
12                            int parentHeight) {
13 
14         super.initialize(width, height, parentWidth, parentHeight);
15         // 设置默认时长
16         setDuration(2000);
17         // 动画结束后保留状态
18         setFillAfter(true);
19         // 设置默认插值器
20         setInterpolator(new BounceInterpolator());
21         mCenterWidth = width / 2;
22         mCenterHeight = height / 2;
23     }
24 
25     // 暴露接口-设置旋转角度
26     public void setRotateY(float rotateY) {
27         mRotateY = rotateY;
28     }
29 
30     @Override
31     protected void applyTransformation(
32             float interpolatedTime,
33             Transformation t) {
34         final Matrix matrix = t.getMatrix();
35         mCamera.save();
36         // 使用Camera设置旋转的角度
37         mCamera.rotateY(mRotateY * interpolatedTime);
38         // 将旋转变换作用到matrix上
39         mCamera.getMatrix(matrix);
40         mCamera.restore();
41         // 通过pre方法设置矩阵作用前的偏移量来改变旋转中心
42         matrix.preTranslate(mCenterWidth, mCenterHeight);
43         matrix.postTranslate(-mCenterWidth, -mCenterHeight);
44     }
45 }

View Code

永利皇宫402 14永利皇宫402 15

public class CustomTV extends Animation {

    private int mCenterWidth;
    private int mCenterHeight;
    private Camera mCamera = new Camera();
    private float mRotateY = 0.0f;

    @Override
    public void initialize(int width,
                           int height,
                           int parentWidth,
                           int parentHeight) {

        super.initialize(width, height, parentWidth, parentHeight);
        // 设置默认时长
        setDuration(1000);
        // 动画结束后保留状态
        setFillAfter(true);
        // 设置默认插值器
        setInterpolator(new AccelerateInterpolator());
        mCenterWidth = width / 2;
        mCenterHeight = height / 2;
    }

    // 暴露接口-设置旋转角度
    public void setRotateY(float rorateY) {
        mRotateY = rorateY;
    }

    @Override
    protected void applyTransformation(
            float interpolatedTime,
            Transformation t) {
        final Matrix matrix = t.getMatrix();
        matrix.preScale(1,
                1 - interpolatedTime,
                mCenterWidth,
                mCenterHeight);
    }
}

View Code

activity 文件的从头到尾的经过:

永利皇宫402 16永利皇宫402 17

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void btnAnim(View view) {
        CustomAnim customAnim = new CustomAnim();
        customAnim.setRotateY(30);
        view.startAnimation(customAnim);
    }

    public void imgClose(View view) {
        CustomTV customTV = new CustomTV();
        view.startAnimation(customTV);
    }
}

View Code

 XML文件:

永利皇宫402 18永利皇宫402 19

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <Button
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="btnAnim"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp" />

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/imageView"
        android:onClick="imgClose"
        android:background="@mipmap/ic_launcher"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

View Code

根本正是多个开关。

View Code

7、LayoutAnimation 

LayoutAnimation 功能于 ViewGroup,为 ViewGroup
制定三个动画,那样当它的子成分出场时都会有这种动画效果。这种成效常常被用于
ListView 上。

LayoutAnimation 也是二个 视图动画,为了给 ViewGroup
子成分加上出演效果,要依据如下多少个步骤。

定义 LayoutAnimation,如下所示:

// res/anim/anim_layout.xml
<layoutAnimation
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:delay="0.5"
    android:animationOrder="reverse"
    android:animation="@anim/anim_item"/>

android:delay 表示子动画的风云延迟。比方登场动画周期是300ms,那么 0.5表示各样子成分都要延缓 150 ms 技巧播放上场动画。

android:animationOrder
表示子动画播放顺序,有二种采取:normal(顺序播放),
reverse(逆序播放)和 random (随机)。

android:animation 代表为子成分制定切实可行的进场动画。

// res/anim/anim_item.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="3000"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:shareInterpolator="true" >

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

    <translate
        android:fromXDelta="1500"
        android:toXDelta="0" />
</set>

接下去为 viewGroup 钦点  android:layoutAnimation
属性:  android:layoutAnimation=”@anim/anim_layout”。那样,它里面包车型地铁子成分就能够有上场动画了。如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutAnimation="@anim/anim_layout">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="shenjaiqi"
        android:id="@+id/shen"/>

</RelativeLayout>

除开运用 xml 内定 LayoutAnimation
外,仍可以透过 LayoutAnimationController 来促成,具体代码如下所示。

ListView listView = (ListView) layout.findViewById(R.id.list);
Animation animation = AnimationUtils.loadAnimation(this,R.anim.anim_item);
LayoutAnimationController controller = new LayoutAnimationController(animation);
controller.setDelay(0.5f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
listView.setLayoutAnimation(controller);

效果:

八、Activity 的切换效果

Activity 有默许的切换效果,不过这一个意义大家得以自定义的,紧要用到 

overridePendingTransition(int enterAnim, int
exitAnim)那么些艺术,这几个艺术必须在 

startActivity 或 finish() 之后被调用能力立见成效,它的参数含义如下:

  enterAnim: Activity 被张开的时候,所需的动画能源 id;

  exitanim:Activity 被关闭的时候,所需的卡通片财富 id;

当运维三个 Activity 的时候,能够依照上边格局丰硕自定义效果:

Intent intent = new Intent(this, TestActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);

当 Activity 推出的时候,也能够依据上面包车型地铁法子丰裕自定义切换效果:

   @Override
  public void finish() {
        super.finish();
        overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);
    }

永利皇宫402 20

选择动画片的注意事项:

一、OOM难题:首要出现在帧动画中,图片较多且大的话极易并发OOM;

二、内部存款和储蓄器泄漏:属性动画中,有一类Infiniti循环的卡通,要在 Activity
退出时立时休憩;视图动画一般不设有此类难题;

叁、包容性难点:动画在 3.0 一下的体系有包容性难题,要做好适配工作;

四、View 动画是对 View 的影响做动画,并不是确实的改换 View
的情景,由此有的时候候会现出动画达成后View 无法藏身的地方,即
setVisibility(View.GONE) 失效了,那年如若调用 view.clearAnimation()
清除 View 动画就可以解决此难点。

5、不要使用px: 尽量使用 dp,

陆、动画成分的互动:在 三.0
以下的种类,动画实现后,仍是在老地点触发单机事件;3.0
初步,属性动画的淡季事件触发为活动后的地方,View 动画不改变。

七、硬件加快:使用进度中,提出拉开硬件加快,进步动画的流畅性。

实例:在导航中应用Logo

永利皇宫402 21永利皇宫402 22

<!DOCTYPE html>  <html lang="en">    <head>      <meta charset="utf-8">      <title>Example icons in navigation with Bootstrap version 2.0 from w3cschool.cc</title>      <meta name="viewport" content="width=device-width, initial-scale=1.0">      <meta name="description" content="Example icons in navigation with Bootstrap version 2.0 from w3cschool.cc">      <meta name="author" content="">        <!-- Le styles -->      <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet">      <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->      <!--[if lt IE 9]>        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>      <![endif]-->        <!-- Le fav and touch icons -->      <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico">      <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png">      <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png">      <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png">    </head>      <body>      <div class="navbar navbar-fixed-top">        <div class="navbar-inner">          <div class="container">            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">                                                      </a>            <a class="brand" href="#">w3cschool</a>            <div class="nav-collapse">              <ul class="nav">                <li class="active"><a href="#"><i class="icon-user icon-white"></i> Home</a></li>                <li><a href="#about"><i class="icon-user icon-white"></i> User</a></li>                <li><a href="#about"><i class="icon-download icon-white"></i> Downlaod</a></li>                <li><a href="#about"><i class="icon-upload icon-white"></i> Upload</a></li>                <li><a href="#about"><i class="icon-play-circle  icon-white"></i> Play Circle</a></li>                <li><a href="#about"><i class="icon-bookmark  icon-white"></i> Bookmark</a></li>                <li><a href="#about"><i class="icon-gift icon-white"></i> Gift</a></li>              </ul>            </div><!--/.nav-collapse -->          </div>        </div>      </div>     <hr>      </div> <!-- /container -->        <!-- Le javascript      ================================================== -->      <!-- Placed at the end of the document so the pages load faster -->      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/jquery.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-transition.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-modal.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-dropdown.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-scrollspy.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tab.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tooltip.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-popover.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-button.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-collapse.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-typeahead.js"></script>      </body>  </html>

View Code

功效如下:

永利皇宫402 23

实例:在开关和开关组中选拔Logo

永利皇宫402 24永利皇宫402 25

<!DOCTYPE html>  <html lang="en">    <head>      <meta charset="utf-8">      <title>Example of using icons in buttons and button groups - Bootstrap version 2.0</title>      <meta name="viewport" content="width=device-width, initial-scale=1.0">      <meta name="description" content="Example of using icons in buttons and button groups - Bootstrap version 2.0 from w3cschool.cc">      <meta name="author" content="">        <!-- Le styles -->      <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet">      <style type="text/css">      form {      margin-top: 50px;      }      </style>      <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->      <!--[if lt IE 9]>        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>      <![endif]-->        <!-- Le fav and touch icons -->      <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico">      <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png">      <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png">      <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png">    </head>    <body>      <div class="container">        <div class="row">      <div class="span4">        <div class="btn-toolbar" style="margin-bottom: 9px">          <div class="btn-group">            <a class="btn" href="#"><i class="icon-align-left"></i></a>            <a class="btn" href="#"><i class="icon-align-center"></i></a>            <a class="btn" href="#"><i class="icon-align-right"></i></a>            <a class="btn" href="#"><i class="icon-align-justify"></i></a>          </div>          <div class="btn-group">            <a class="btn btn-primary" href="#"><i class="icon-user icon-white"></i> User</a>            <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"></a>            <ul class="dropdown-menu">              <li><a href="#"><i class="icon-pencil"></i> Edit</a></li>              <li><a href="#"><i class="icon-trash"></i> Delete</a></li>              <li><a href="#"><i class="icon-ban-circle"></i> Ban</a></li>              <li class="divider"></li>              <li><a href="#"><i class="i"></i> Make admin</a></li>            </ul>          </div>        </div>        <p>          <a class="btn" href="#"><i class="icon-refresh"></i> Refresh</a>          <a class="btn btn-success" href="#"><i class="icon-shopping-cart icon-white"></i> Checkout</a>          <a class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Delete</a>        </p>        <p>          <a class="btn btn-large" href="#"><i class="icon-comment"></i> Comment</a>          <a class="btn btn-small" href="#"><i class="icon-cog"></i> Settings</a>          <a class="btn btn-small btn-info" href="#"><i class="icon-info-sign icon-white"></i> More Info</a>        </p>      </div>         </div>      </div>       <!-- Le javascript      ================================================== -->      <!-- Placed at the end of the document so the pages load faster -->      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/jquery.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-transition.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-modal.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-dropdown.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-scrollspy.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tab.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tooltip.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-popover.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-button.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-collapse.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js"></script>      <script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-typeahead.js"></script>  </body>  </html>

View Code

效益如下:

永利皇宫402 26


发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图