首页 > 编程知识 正文

android缩放动画中心缩放,android实现字体大小调整

时间:2023-05-05 00:02:57 阅读:60989 作者:108

什么是呼叫动画

比例动画是一种缩放动画,应用场景特别多,如常见的隐藏菜单点击显示

分为两种方法介绍ScaleAnimation的使用方法。

1. xml文件形式

文件名: anim_scale_in.xml

效果:显示view放大显示效果

源代码:

? XML版本=' 1.0 '编码=' utf-8 '? setxmlns 3360 Android=' http://schemas.Android.com/apk/RES/Android ' scale Android 3360 INTERPOL ator=' @ Android 3360 ecelerate _ INTERPOL ator ' Android 3360 duration=' 1000 ' Android :=' 0.0 '0pivotx=' 50 % ' Android : pivoty=' 50 % ' Android 3360 to xscale=' 1.0 ' Android 3360 toy scale=' 1.0 '/set属性解例如,fromXScale=0.5表示将从其x轴长度的0.5倍到interpolator:缩放到其x轴长度的多少倍后结束。 例如,像toxscale (那样

上述两个意思是,该视图的x轴从其x轴长度的0.5倍开始变焦到其x轴长度的2倍,从fromXScale:其y轴长度的多少倍开始变焦,例如,fromYScale=0.5,其中:指示其将缩放到其y轴长度的倍数而结束,例如,toYScale=2.0指示x轴缩放到其y轴长度的两倍而结束的http://www.Sina.com/3358 ww.com.http://

例如,pivotX=50%,pivotY=50%表示从控件的中心开始缩放

//从控件的左下角开始Android : pivotx='0' Android : pivoty=' 100 % '//从控件的左上角开始,显示Android 3360 pivotx='0' Android 3360 pivoty='0'的控件的右下角为Android 3360 pivotx=' 100 % ' Android 3360 pivoty='

? XML版本=' 1.0 '编码=' utf-8 '? setxmlns 3360 Android=' http://schemas.Android.com/apk/RES/安卓' scale Android 3360 INTERPOL ator=' @ Android 3360 accelerate _ INTERPOL ator ' Android 3360 duration=' 1000 ' Android : e=' 1.0 '0pivotx=' 50 % '安卓: pivoty=' 50 % '安卓3360 to xscale='0'安卓3360 toy scale='0'/set

toXScale

/** *放大的动画* * @param context * @param view目标view */publicstaticvoidstartscaleinanim (上下文,view If (视图!=null(view.start

Animation(animation); } /** * 缩放缩小动画 * * @param context * @param view 目标view */ public static void startScaleOutAnim(Context context, View view) { Animation animation = AnimationUtils.loadAnimation(context, R.anim.anim_scale_out); if (view != null) view.startAnimation(animation); }

我单独封装在一个动画工具类中,哪里需要就哪里调用。

下面看看代码的执行效果:

缩放同时还可以添加透明度变化,如下:

放大+淡入:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/decelerate_interpolator" android:duration="1000" android:fillAfter="true" android:fillEnabled="true" android:fromXScale="0" android:fromYScale="0" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" /> <!--同时配置淡入功能--> <alpha android:duration="700" android:fillAfter="true" android:fromAlpha="0" android:toAlpha="1" /></set>

缩小+淡出

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_interpolator" android:duration="1000" android:fillAfter="true" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:toXScale="0" android:toYScale="0" /> <!--同时配置淡出功能--> <alpha android:duration="700" android:fillAfter="true" android:fromAlpha="1" android:toAlpha="0" /></set>

效果如下:

下拉菜单显示与收回,效果:

显示:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/decelerate_interpolator" android:duration="300" android:fillAfter="true" android:fillEnabled="true" android:fromXScale="1.0" android:fromYScale="0" android:pivotX="100%" android:pivotY="0" android:toXScale="1.0" android:toYScale="1.0" /> <!--同时配置淡入功能--> <alpha android:duration="300" android:fillAfter="true" android:fromAlpha="0" android:toAlpha="1" /></set>

收起:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_interpolator" android:duration="300" android:fillAfter="true" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="100%" android:pivotY="0" android:toXScale="1.0" android:toYScale="0" /> <!--同时配置淡出功能--> <alpha android:duration="300" android:fillAfter="true" android:fromAlpha="1" android:toAlpha="0" /></set>

效果:

缩放下拉与收回效果:

显示:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/decelerate_interpolator" android:duration="200" android:fillAfter="true" android:fillEnabled="true" android:fromXScale="0" android:fromYScale="0" android:pivotX="100%" android:pivotY="0" android:toXScale="1.0" android:toYScale="1.0" /> <!--同时配置淡入功能--> <alpha android:duration="200" android:fillAfter="true" android:fromAlpha="0" android:toAlpha="1" /></set>

收起:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_interpolator" android:duration="200" android:fillAfter="true" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="100%" android:pivotY="0" android:toXScale="0" android:toYScale="0" /> <!--同时配置淡出功能--> <alpha android:duration="200" android:fillAfter="true" android:fromAlpha="1" android:toAlpha="0" /></set>

效果:

类似游戏按钮的按下放大再还原效果:

public static void animScaleIn(View view){ //缩放动画 ScaleAnimation animation = new ScaleAnimation(1,1.2f,1,1.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); animation.setDuration(100); animation.setFillAfter(true); animation.setRepeatMode(Animation.REVERSE); animation.setRepeatCount(1); //透明度动画 AlphaAnimation animation1 = new AlphaAnimation(1,0.8f); animation1.setDuration(100); animation1.setRepeatCount(1); animation1.setRepeatMode(Animation.REVERSE); animation1.setFillAfter(true); //装入AnimationSet中 AnimationSet set = new AnimationSet(true); set.addAnimation(animation); set.addAnimation(animation1); if (view != null) view.startAnimation(set); }

效果如下:

备注:由于我的图片是导出视频再用PS转换成的gif,故效率上有所损失,实际动画效果和速度比图片的快。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。