动画设置

来源:互联网 发布:淘宝复制链接没有响应 编辑:程序博客网 时间:2024/06/03 21:02
//位移动画
public void trans(View view){        //使用代码创建位移的动画....Translate位移        TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);                //动画要执行需要指定执行的时间        translateAnimation.setDuration(3000);        //重复执行动画....设置重复的次数        translateAnimation.setRepeatCount(1);        //设置重复执行的模式        /**         * Animation.RESTART重新再次执行动画,,,默认就是这种形式         * Animation.REVERSE反过来再次执行动画         *          * 重复的模式只在重复次数大于0的时候起作用,,,,或者重复次数设置为 INFINITE         *          * Animation.INFINITE无限次循环         */        translateAnimation.setRepeatMode(Animation.REVERSE);                //开始动画        imageView.startAnimation(translateAnimation);            }

//缩放动画
public void scale(View view) {        /**         * pivotXType, 中心点x轴的类型         * pivotXValue,          * pivotYType,          * pivotYValue         */        ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);                scaleAnimation.setDuration(3000);                //设置动画结束之后保持结束的状态        scaleAnimation.setFillAfter(true);                imageView.startAnimation(scaleAnimation);    } 

//透明度变化

public void ala(View view) {        /**         * fromAlpha,开始的透明度         *  toAlpha,,结束的         */        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);                alphaAnimation.setDuration(3000);                imageView.startAnimation(alphaAnimation);            }

//旋转动画

    /**     * fromDegrees, 起始的角度     * toDegrees, 终点的角度     * pivotXType, 中心x轴的类型     * pivotXValue, 中心x轴的值     * pivotYType,      * pivotYValue     * @param view     */    public void rotate(View view) {        RotateAnimation rotateAnimation = new RotateAnimation(0, -360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);                rotateAnimation.setDuration(3000);                imageView.startAnimation(rotateAnimation);    } 
//组合动画

    public void zuhe(View view) {        TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);        ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);        RotateAnimation rotateAnimation = new RotateAnimation(0, -360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);                //创建一个组合动画...AnimationSet...shareInterpolator插值器(设置插值器可以是动画产生加速效果)        //给组合添加动画        AnimationSet animationSet = new AnimationSet(true);//组合动画是否共同使用一个插值器        animationSet.addAnimation(scaleAnimation);        animationSet.addAnimation(alphaAnimation);        animationSet.addAnimation(rotateAnimation);        //位移动画        animationSet.addAnimation(translateAnimation);                //设置时间        animationSet.setDuration(3000);        imageView.startAnimation(animationSet);    }

//Activity的跳转动画
public void tiaozhuan(View view) {        Intent intent = new Intent(MainActivity.this,AecondActivity.class);                startActivity(intent);                //给跳转加动画        /**         *只需要在启动Activity后使用overridePendingTransition方法传入anim的id即可完成Activity的切换动画效果。         * int enterAnim, 进入的动画,,,第二个界面的动画...xml资源文件下的动画的id         * int exitAnim,,,第一个界面出去的动画         */        overridePendingTransition(R.anim.anim_in, R.anim.anim_out);                //overridePendingTransition(R.anim.trans_in, R.anim.trans_out);    }

//在value下创建anim文件anim_in.xml/anim_out.xml

//创建进入和退出的动画

<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="3000"    android:fromAlpha="0"    android:toAlpha="1" ></alpha>
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="3000"    android:fromAlpha="1"    android:toAlpha="0" ></alpha>

//位移
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="3000"    android:fromXDelta="100%p"    android:fromYDelta="0"    android:toXDelta="0"    android:toYDelta="0" >    <!-- 在xml动画文件中没有type这个属性,,,,100%p代表着相对父窗体,,,100%相对自己,,,50.0f数值就是一个绝对的类型 --></translate>
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="3000"    android:fromXDelta="0"    android:fromYDelta="0"    android:toXDelta="-100%p"    android:toYDelta="0" ></translate>








原创粉丝点击