郑州网站建设开发,网站建设职位名称,龙海网站建设哪家好,html网页制作代码作业前言#xff1a;这几天做客户回访#xff0c;感触很大#xff0c;用户只要是留反馈信息#xff0c;总是一种恨铁不成钢的心态#xff0c;想用你的app#xff0c;却是因为你的技术问题#xff0c;让他们不得不放弃#xff0c;而你一个回访电话却让他们尽释前嫌#xff… 前言这几天做客户回访感触很大用户只要是留反馈信息总是一种恨铁不成钢的心态想用你的app却是因为你的技术问题让他们不得不放弃而你一个回访电话却让他们尽释前嫌当最后把手机号留给他们以便随时沟通的时候总会发来一条条的鼓励短信让我不自主的开始内疚。哎多么可爱的用户多么无耐的现实。 相关文章 《Android自定义控件三部曲文章索引》http://blog.csdn.net/harvic880925/article/details/50995268 一、概述 Android的animation由四种类型组成alpha、scale、translate、rotate对应android官方文档地址《Animation Resources》 1、XML配置文件中 alpha渐变透明度动画效果scale渐变尺寸伸缩动画效果translate画面转换位置移动动画效果rotate画面转移旋转动画效果 下面我们逐个讲讲每个标签的属性及用法。 2、动作文件存放位置 动作定义文件应该存放在res/anim文件夹下访问时采用R.anim.XXX.xml的方式位置如图 二、scale标签——调节尺寸 1、自有属性 scale标签是缩放动画可以实现动态调控件尺寸的效果有下面几个属性 android:fromXScale 起始的X方向上相对自身的缩放比例浮点值比如1.0代表自身无变化0.5代表起始时缩小一倍2.0代表放大一倍android:toXScale 结尾的X方向上相对自身的缩放比例浮点值android:fromYScale 起始的Y方向上相对自身的缩放比例浮点值android:toYScale 结尾的Y方向上相对自身的缩放比例浮点值android:pivotX 缩放起点X轴坐标可以是数值、百分数、百分数p 三种样式比如 50、50%、50%p当为数值时表示在当前View的左上角即原点处加上50px做为起始缩放点如果是50%表示在当前控件的左上角加上自己宽度的50%做为起始点如果是50%p那么就是表示在当前的左上角加上父控件宽度的50%做为起始点x轴坐标。具体意义后面会举例演示android:pivotY 缩放起点Y轴坐标取值及意义跟android:pivotX一样。下面看一个实例当scale里的属性这样设置时效果会怎样呢 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50 android:pivotY50 android:duration700 / 1、pivotX取值数值时50 这个控件宽度和高度都是从0放大到1.4倍起始点坐标在控件左上角坐标原点向x轴正方向和y轴正方向都加上50像素 根据pivotX,pivotY的意义控件的左上角即为控件的坐标原点这里的起始点是在控件的原点的基础上向X轴和Y轴各加上50px做为起始点如下图中图二所示 图一 图二 2、pivotX取值百分数时50%下面再看看当pivotX、pivotY取百分数的时候起始点又在哪里 上面我们讲了pivotX的值当取50%时表示在原点坐标的基础上加上的自己宽度的50%看看效果 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50% android:pivotY50% android:duration700 / 缩放位置大小仍然从0-1.4只改变pivotX和pivotY;起始点位置如下图中图二所示 图一 图二 3、pivotX取值50%p时 前面说过当取值在百分数后面加上一个字母p就表示取值的基数是父控件即在原点的基础上增加的值是父标签的百分值。 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50%p android:pivotY50%p android:duration700 / 效果图及起始点坐标图如下所示 2、从Animation类继承的属性 Animation类是所有动画scale、alpha、translate、rotate的基类这里以scale标签为例讲解一下Animation类所具有的属性及意义。关于Animation类的官方文档位置为《Animation》 android:duration 动画持续时间以毫秒为单位 android:fillAfter 如果设置为true控件动画结束时将保持动画最后时的状态android:fillBefore 如果设置为true,控件动画结束时还原到开始动画前的状态android:fillEnabled 与android:fillBefore 效果相同都是在动画结束时将控件还原到初始化状态android:repeatCount 重复次数android:repeatMode 重复类型有reverse和restart两个值reverse表示倒序回放restart表示重新放一遍必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型即回放时的动作。android:interpolator 设定插值器其实就是指定的动作效果比如弹跳效果等不在这小节中讲解后面会单独列出一单讲解。对于android:duration就不再讲解了就是动画的持续时长以毫秒为单位下面看看android:fillAfter和android:fillBefore (1)android:fillAfter:保持动画结束的状态 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50% android:pivotY50% android:duration700 android:fillAftertrue / 2android:fillBefore 还原初始化状态 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50% android:pivotY50% android:duration700 android:fillBeforetrue / android:fillBeforetrue android:fillEnabletrue 上面顺便列出了当仅设定fillEanble为true时的效果这两个的标签的效果完全相同。 3、android:repeatModerestart /reverse 设定回放类型 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50% android:pivotY50% android:duration700 android:fillBeforetrue android:repeatCount1 android:repeatModerestart / androidRepeatMode设为restart androidRepeatMode设为reverse 三、alpha标签——调节透明度 1、自身属性 android:fromAlpha 动画开始的透明度从0.0 --1.0 0.0表示全透明1.0表示完全不透明android:toAlpha 动画结束时的透明度也是从0.0 --1.0 0.0表示全透明1.0表示完全不透明 使用示例 [html] view plaincopy ?xml version1.0 encodingutf-8? alpha xmlns:androidhttp://schemas.android.com/apk/res/android android:fromAlpha1.0 android:toAlpha0.1 android:duration3000 android:fillBeforetrue /alpha 2、从Animation类继承的属性 android:duration 动画持续时间以毫秒为单位 android:fillAfter 如果设置为true控件动画结束时将保持动画最后时的状态android:fillBefore 如果设置为true,控件动画结束时还原到开始动画前的状态android:fillEnabled 与android:fillBefore 效果相同都是在动画结束时将控件还原到初始化状态android:repeatCount 重复次数android:repeatMode 重复类型有reverse和restart两个值reverse表示倒序回放restart表示重新放一遍必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型即回放时的动作。android:interpolator 设定插值器其实就是指定的动作效果比如弹跳效果等不在这小节中讲解后面会单独列出一单讲解。 与scale标签意义一样就不再缀述。 四、rotate标签——旋转 1、自身属性 android:fromDegrees 开始旋转的角度位置正值代表顺时针方向度数负值代码逆时针方向度数android:toDegrees 结束时旋转到的角度位置正值代表顺时针方向度数负值代码逆时针方向度数android:pivotX 缩放起点X轴坐标可以是数值、百分数、百分数p 三种样式比如 50、50%、50%p具体意义已在scale标签中讲述这里就不再重讲android:pivotY 缩放起点Y轴坐标可以是数值、百分数、百分数p 三种样式比如 50、50%、50%p [html] view plaincopy ?xml version1.0 encodingutf-8? rotate xmlns:androidhttp://schemas.android.com/apk/res/android android:fromDegrees0 android:toDegrees-650 android:pivotX50% android:pivotY50% android:duration3000 android:fillAftertrue /rotate 围绕自身从0度逆时针旋转650度 围绕自身从0度顺时针旋转650度 android:fromDegrees0 android:fromDegrees0 android:toDegrees-650 android:toDegrees650 2、从Animation类继承的属性 android:duration 动画持续时间以毫秒为单位 android:fillAfter 如果设置为true控件动画结束时将保持动画最后时的状态android:fillBefore 如果设置为true,控件动画结束时还原到开始动画前的状态android:fillEnabled 与android:fillBefore 效果相同都是在动画结束时将控件还原到初始化状态android:repeatCount 重复次数android:repeatMode 重复类型有reverse和restart两个值reverse表示倒序回放restart表示重新放一遍必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型即回放时的动作。android:interpolator 设定插值器其实就是指定的动作效果比如弹跳效果等不在这小节中讲解后面会单独列出一单讲解。 与scale标签意义一样就不再缀述。 五、translate标签 —— 平移 1、自身属性 android:fromXDelta 起始点X轴坐标可以是数值、百分数、百分数p 三种样式比如 50、50%、50%p具体意义已在scale标签中讲述这里就不再重讲android:fromYDelta 起始点Y轴从标可以是数值、百分数、百分数p 三种样式android:toXDelta 结束点X轴坐标android:toYDelta 结束点Y轴坐标 [html] view plaincopy ?xml version1.0 encodingutf-8? translate xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXDelta0 android:toXDelta-80 android:fromYDelta0 android:toYDelta-80 android:duration2000 android:fillBeforetrue /translate 2、从Animation类继承的属性 android:duration 动画持续时间以毫秒为单位 android:fillAfter 如果设置为true控件动画结束时将保持动画最后时的状态android:fillBefore 如果设置为true,控件动画结束时还原到开始动画前的状态android:fillEnabled 与android:fillBefore 效果相同都是在动画结束时将控件还原到初始化状态android:repeatCount 重复次数android:repeatMode 重复类型有reverse和restart两个值reverse表示倒序回放restart表示重新放一遍必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型即回放时的动作。android:interpolator 设定插值器其实就是指定的动作效果比如弹跳效果等不在这小节中讲解后面会单独列出一单讲解。 与scale标签意义一样就不再缀述。 六、set标签——定义动作合集 前面我们讲解了各个标签动画的意义及用法但他们都是独立对控件起作用假设我现在想上面的textView控件做一个动画——从小到大旋转出场而且透明度也要从0变成1即下面的这个效果该怎么办 这就需要对指定的控件定义动作合集Set标签就可以将几个不同的动作定义成一个组 属性 set标签自已是没有属性的他的属性都是从Animation继承而来但当它们用于Set标签时就会对Set标签下的所有子控件都产生作用。 属性有从Animation类继承的属性 android:duration 动画持续时间以毫秒为单位 android:fillAfter 如果设置为true控件动画结束时将保持动画最后时的状态android:fillBefore 如果设置为true,控件动画结束时还原到开始动画前的状态android:fillEnabled 与android:fillBefore 效果相同都是在动画结束时将控件还原到初始化状态android:repeatCount 重复次数android:repeatMode 重复类型有reverse和restart两个值reverse表示倒序回放restart表示重新放一遍必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型即回放时的动作。android:interpolator 设定插值器其实就是指定的动作效果比如弹跳效果等不在这小节中讲解后面会单独列出一单讲解。 与scale标签意义一样就不再缀述。 上面这个效果所对应的XML代码为 [html] view plaincopy ?xml version1.0 encodingutf-8? set xmlns:androidhttp://schemas.android.com/apk/res/android android:duration3000 android:fillAftertrue alpha android:fromAlpha0.0 android:toAlpha1.0/ scale android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50% android:pivotY50%/ rotate android:fromDegrees0 android:toDegrees720 android:pivotX50% android:pivotY50%/ /set 七、实例——如何将动画XML文件应用于控件中 上面我仅仅是列出了每个标签及其属性的意义及应用之后的效果演示但上面是如何将定义动画的xml应用到textView控件中的却迟迟没说这一小节就以scale动画为例讲述如何将定义好的scle动作添加到指定控件中。 先看最终效果图 1、新建工程、新建scale动画文件scaleanim.xml 新建一个工程并且在res文件夹下新建一个anim文件夹然后再新建一个scaleanim.xml文件结构如图所示 scaleanim.xml的代码为从TextView中心点从0放大到1.4倍反复一次最后还原到初始化状态 [html] view plaincopy ?xml version1.0 encodingutf-8? scale xmlns:androidhttp://schemas.android.com/apk/res/android android:fromXScale0.0 android:toXScale1.4 android:fromYScale0.0 android:toYScale1.4 android:pivotX50% android:pivotY50% android:duration700 android:fillBeforetrue android:repeatCount1 android:repeatModerestart / 2、XML布局文件 [html] view plaincopy LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android xmlns:toolshttp://schemas.android.com/tools android:layout_widthmatch_parent android:layout_heightmatch_parent android:orientationvertical tools:contextcom.harvic.animation_demo.MainActivity Button android:idid/btn_animation android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_margin10dip android:textscale animation/ TextView android:idid/tv android:layout_width100dip android:layout_height200dip android:background#ff00ff android:textstring/hello_world android:layout_gravitycenter_horizontal/ /LinearLayout 3、JAVA代码 [java] view plaincopy public class MainActivity extends Activity { Button scaleBtn ; Animation scaleAnimation; TextView tv; Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); scaleAnimation AnimationUtils.loadAnimation(this, R.anim.scaleanim); scaleBtn (Button)findViewById(R.id.btn_animation); tv (TextView)findViewById(R.id.tv); scaleBtn.setOnClickListener(new View.OnClickListener() { Override public void onClick(View v) { // TODO Auto-generated method stub tv.startAnimation(scaleAnimation); } }); } } 1通过scaleAnimation AnimationUtils.loadAnimation(this, R.anim.scaleanim);从XML文件中获取动画 2利用startAnimation将动画传递给指定控件显示。 至此本文就结束了下篇将讲述有关插值器的相关属性及意义。 下面就是源码下载了源码中包含两部分内容 1、Harvic_animation_demo工程是第七部分的实例源码 2、tryAlpha_xml工程是前六节动作代码的集合包含了前六小节里的所有代码及动画定义。 源码下载地址http://download.csdn.net/detail/harvic880925/8032579 请大家尊重原创者版权转载请标明出处http://blog.csdn.net/harvic880925/article/details/39996643 谢谢 转载于:https://www.cnblogs.com/Free-Thinker/p/6214300.html