zoukankan      html  css  js  c++  java
  • Android 动画之ScaleAnimation应用详解

    1. android中提供了4中动画:   
    2. AlphaAnimation 透明度动画效果   
    3. ScaleAnimation 缩放动画效果   
    4. TranslateAnimation 位移动画效果   
    5. RotateAnimation 旋转动画效果   
    6.   
    7. 本节讲解ScaleAnimation 动画,   
    8. ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)   
    9. 参数说明:   
    10.   
    11. 复制代码 代码如下:  
    12.   
    13. float fromX 动画起始时 X坐标上的伸缩尺寸   
    14. float toX 动画结束时 X坐标上的伸缩尺寸   
    15. float fromY 动画起始时Y坐标上的伸缩尺寸   
    16. float toY 动画结束时Y坐标上的伸缩尺寸   
    17. int pivotXType 动画在X轴相对于物件位置类型   
    18. float pivotXValue 动画相对于物件的X坐标的开始位置   
    19. int pivotYType 动画在Y轴相对于物件位置类型   
    20. float pivotYValue 动画相对于物件的Y坐标的开始位置   
    21.   
    22.   
    23. 代码:   
    24.   
    25. 复制代码 代码如下:  
    26.   
    27. public class MainActivity extends Activity {   
    28. ImageView image;   
    29. Button start;   
    30. Button cancel;   
    31. @Override   
    32. public void onCreate(Bundle savedInstanceState) {   
    33. super.onCreate(savedInstanceState);   
    34. setContentView(R.layout.activity_main);   
    35. image = (ImageView) findViewById(R.id.main_img);   
    36. start = (Button) findViewById(R.id.main_start);   
    37. cancel = (Button) findViewById(R.id.main_cancel);   
    38. /** 设置缩放动画 */   
    39. final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,   
    40. Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);   
    41. animation.setDuration(2000);//设置动画持续时间   
    42. /** 常用方法 */   
    43. //animation.setRepeatCount(int repeatCount);//设置重复次数   
    44. //animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态   
    45. //animation.setStartOffset(long startOffset);//执行前的等待时间   
    46. start.setOnClickListener(new OnClickListener() {   
    47. public void onClick(View arg0) {   
    48. image.setAnimation(animation);   
    49. /** 开始动画 */   
    50. animation.startNow();   
    51. }   
    52. });   
    53. cancel.setOnClickListener(new OnClickListener() {   
    54. public void onClick(View v) {   
    55. /** 结束动画 */   
    56. animation.cancel();   
    57. }   
    58. });   
    59. }   
    60. }  
    1. 本节讲解ScaleAnimation 动画,   
    2. ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)   
    3. 参数说明:   
    4. 复制代码 代码如下:  
    5. float fromX 动画起始时 X坐标上的伸缩尺寸   
    6. float toX 动画结束时 X坐标上的伸缩尺寸   
    7. float fromY 动画起始时Y坐标上的伸缩尺寸   
    8. float toY 动画结束时Y坐标上的伸缩尺寸   
    9. int pivotXType 动画在X轴相对于物件位置类型   
    10. float pivotXValue 动画相对于物件的X坐标的开始位置   
    11. int pivotYType 动画在Y轴相对于物件位置类型   
    12. float pivotYValue 动画相对于物件的Y坐标的开始位置   
    13.   
    14. 代码:   
    15. 复制代码 代码如下:  
    16. public class MainActivity extends Activity {   
    17. ImageView image;   
    18. Button start;   
    19. Button cancel;   
    20. @Override   
    21. public void onCreate(Bundle savedInstanceState) {   
    22. super.onCreate(savedInstanceState);   
    23. setContentView(R.layout.activity_main);   
    24. image = (ImageView) findViewById(R.id.main_img);   
    25. start = (Button) findViewById(R.id.main_start);   
    26. cancel = (Button) findViewById(R.id.main_cancel);   
    27. /** 设置缩放动画 */   
    28. final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,   
    29. Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);   
    30. animation.setDuration(2000);//设置动画持续时间   
    31. /** 常用方法 */   
    32. //animation.setRepeatCount(int repeatCount);//设置重复次数   
    33. //animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态   
    34. //animation.setStartOffset(long startOffset);//执行前的等待时间   
    35. start.setOnClickListener(new OnClickListener() {   
    36. public void onClick(View arg0) {   
    37. image.setAnimation(animation);   
    38. /** 开始动画 */   
    39. animation.startNow();   
    40. }   
    41. });   
    42. cancel.setOnClickListener(new OnClickListener() {   
    43. public void onClick(View v) {   
    44. /** 结束动画 */   
    45. animation.cancel();   
    46. }   
    47. });   
    48. }   
    49. }  
    [javascript] view plaincopyprint?在CODE上查看代码片派生到我的代码片
     
    1.    
    [javascript] view plaincopyprint?在CODE上查看代码片派生到我的代码片
     
    1. 本节讲解RotateAnimation 动画,   
    2. RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)   
    3. 参数说明:   
    4. float fromDegrees:旋转的开始角度。   
    5. float toDegrees:旋转的结束角度。   
    6. int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。   
    7. float pivotXValue:X坐标的伸缩值。   
    8. int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。   
    9. float pivotYValue:Y坐标的伸缩值。   
    10. 代码:   
    11. <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code17269" class="codebody">  
    12. public class MainActivity extends Activity {   
    13. ImageView image;   
    14. Button start;   
    15. Button cancel;   
    16. @Override   
    17. public void onCreate(Bundle savedInstanceState) {   
    18. super.onCreate(savedInstanceState);   
    19. setContentView(R.layout.activity_main);   
    20. image = (ImageView) findViewById(R.id.main_img);   
    21. start = (Button) findViewById(R.id.main_start);   
    22. cancel = (Button) findViewById(R.id.main_cancel);   
    23. /** 设置旋转动画 */   
    24. final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,   
    25. 0.5f,Animation.RELATIVE_TO_SELF,0.5f);   
    26. animation.setDuration(3000);//设置动画持续时间   
    27. /** 常用方法 */   
    28. //animation.setRepeatCount(int repeatCount);//设置重复次数   
    29. //animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态   
    30. //animation.setStartOffset(long startOffset);//执行前的等待时间   
    31. start.setOnClickListener(new OnClickListener() {   
    32. public void onClick(View arg0) {   
    33. image.setAnimation(animation);   
    34. /** 开始动画 */   
    35. animation.startNow();   
    36. }   
    37. });   
    38. cancel.setOnClickListener(new OnClickListener() {   
    39. public void onClick(View v) {   
    40. /** 结束动画 */   
    41. animation.cancel();   
    42. }   
    43. });   
    44. }   
    45. } </div>  
    [javascript] view plaincopyprint?在CODE上查看代码片派生到我的代码片
     
    1. 本节讲解TranslateAnimation动画,TranslateAnimation比较常用,比如QQ,网易新闻菜单条的动画,就可以用TranslateAnimation实现,   
    2. 通过TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 来定义动画   
    3.   
    4. 参数说明:   
    5. <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code3207" class="codebody">  
    6. float fromXDelta 动画开始的点离当前View X坐标上的差值   
    7. float toXDelta 动画结束的点离当前View X坐标上的差值   
    8. float fromYDelta 动画开始的点离当前View Y坐标上的差值   
    9. float toYDelta 动画开始的点离当前View Y坐标上的差值   
    10. </div>  
    11. 常用方法:   
    12. <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code94921" class="codebody">  
    13. animation.setDuration(long durationMillis);//设置动画持续时间   
    14. animation.setRepeatCount(int i);//设置重复次数   
    15. animation.setRepeatMode(Animation.REVERSE);//设置反方向执行   
    16. </div>  
    17. Xml属性:   
    18. <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code72894" class="codebody">  
    19. android:duration:运行动画的时间   
    20. android:repeatCount:定义动画重复的时间   
    21. </div>  
    22. 代码:   
    23. <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code12415" class="codebody">  
    24. public class MainActivity extends Activity {   
    25. ImageView image;   
    26. Button start;   
    27. Button cancel;   
    28. @Override   
    29. public void onCreate(Bundle savedInstanceState) {   
    30. super.onCreate(savedInstanceState);   
    31. setContentView(R.layout.activity_main);   
    32. image = (ImageView) findViewById(R.id.main_img);   
    33. start = (Button) findViewById(R.id.main_start);   
    34. cancel = (Button) findViewById(R.id.main_cancel);   
    35. /** 设置位移动画 向右位移150 */   
    36. final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0);   
    37. animation.setDuration(2000);//设置动画持续时间   
    38. animation.setRepeatCount(2);//设置重复次数   
    39. animation.setRepeatMode(Animation.REVERSE);//设置反方向执行   
    40. start.setOnClickListener(new OnClickListener() {   
    41. public void onClick(View arg0) {   
    42. image.setAnimation(animation);   
    43. /** 开始动画 */   
    44. animation.startNow();   
    45. }   
    46. });   
    47. cancel.setOnClickListener(new OnClickListener() {   
    48. public void onClick(View v) {   
    49. /** 结束动画 */   
    50. animation.cancel();   
    51. }   
    52. });   
    53. }   
    54. } </div><div class="codebody"> </div><div class="codebody"> </div><div class="codebody"> </div><div class="codebody"> </div>  
    [javascript] view plaincopyprint?在CODE上查看代码片派生到我的代码片
     
    1. <pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code">本节讲解AlphaAnimation 动画,窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation。   
    2. 直接看代码:   
    3. 复制代码 代码如下:  
    4. public class MainActivity extends Activity {   
    5. ImageView image;   
    6. Button start;   
    7. Button cancel;   
    8. @Override   
    9. public void onCreate(Bundle savedInstanceState) {   
    10. super.onCreate(savedInstanceState);   
    11. setContentView(R.layout.activity_main);   
    12. image = (ImageView) findViewById(R.id.main_img);   
    13. start = (Button) findViewById(R.id.main_start);   
    14. cancel = (Button) findViewById(R.id.main_cancel);   
    15. /** 设置透明度渐变动画 */   
    16. final AlphaAnimation animation = new AlphaAnimation(1, 0);   
    17. animation.setDuration(2000);//设置动画持续时间   
    18. /** 常用方法 */   
    19. //animation.setRepeatCount(int repeatCount);//设置重复次数   
    20. //animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态   
    21. //animation.setStartOffset(long startOffset);//执行前的等待时间   
    22. start.setOnClickListener(new OnClickListener() {   
    23. public void onClick(View arg0) {   
    24. image.setAnimation(animation);   
    25. /** 开始动画 */   
    26. animation.startNow();   
    27. }   
    28. });   
    29. cancel.setOnClickListener(new OnClickListener() {   
    30. public void onClick(View v) {   
    31. /** 结束动画 */   
    32. animation.cancel();   
    33. }   
    34. });   
    35. }   
    36. }</pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code"> </pre><br>  
    37. <pre></pre>  
    38. <p></p>  
    39. <p> </p>  
    40. <p> </p>  
    41. <p> </p>  
    42. <p> </p>  
    43. <p> </p>  
    44. <pre></pre>  
    45.      
  • 相关阅读:
    Codeforces 919D:Substring(拓扑排序+DP)
    初学Javascript,写一个简易的登陆框
    学习数据结构之线性表
    用python实现的简易记牌器的demo
    Multiism四阶巴特沃兹低通滤波器的仿真实现
    用python来抓取“煎蛋网”上面的美女图片,尺度很大哦!哈哈
    用Python爬虫爬取“女神吧”上的照片。
    在linux操作系统上进行简单的C语言源码的gcc编译实验
    想学习linux操作系统,于是选择了在win8 虚拟机VM player 里装了Linux版本Centos7
    通过python的urllib.request库来爬取一只猫
  • 原文地址:https://www.cnblogs.com/wangfeng520/p/5006964.html
Copyright © 2011-2022 走看看