-
Android 动画之ScaleAnimation应用详解
- android中提供了4中动画:
- AlphaAnimation 透明度动画效果
- ScaleAnimation 缩放动画效果
- TranslateAnimation 位移动画效果
- RotateAnimation 旋转动画效果
-
- 本节讲解ScaleAnimation 动画,
- ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
- 参数说明:
-
- 复制代码 代码如下:
-
- float fromX 动画起始时 X坐标上的伸缩尺寸
- float toX 动画结束时 X坐标上的伸缩尺寸
- float fromY 动画起始时Y坐标上的伸缩尺寸
- float toY 动画结束时Y坐标上的伸缩尺寸
- int pivotXType 动画在X轴相对于物件位置类型
- float pivotXValue 动画相对于物件的X坐标的开始位置
- int pivotYType 动画在Y轴相对于物件位置类型
- float pivotYValue 动画相对于物件的Y坐标的开始位置
-
-
- 代码:
-
- 复制代码 代码如下:
-
- public class MainActivity extends Activity {
- ImageView image;
- Button start;
- Button cancel;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- image = (ImageView) findViewById(R.id.main_img);
- start = (Button) findViewById(R.id.main_start);
- cancel = (Button) findViewById(R.id.main_cancel);
- final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
- Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- animation.setDuration(2000);
- start.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- image.setAnimation(animation);
- animation.startNow();
- }
- });
- cancel.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- animation.cancel();
- }
- });
- }
- }
- 本节讲解ScaleAnimation 动画,
- ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
- 参数说明:
- 复制代码 代码如下:
- float fromX 动画起始时 X坐标上的伸缩尺寸
- float toX 动画结束时 X坐标上的伸缩尺寸
- float fromY 动画起始时Y坐标上的伸缩尺寸
- float toY 动画结束时Y坐标上的伸缩尺寸
- int pivotXType 动画在X轴相对于物件位置类型
- float pivotXValue 动画相对于物件的X坐标的开始位置
- int pivotYType 动画在Y轴相对于物件位置类型
- float pivotYValue 动画相对于物件的Y坐标的开始位置
-
- 代码:
- 复制代码 代码如下:
- public class MainActivity extends Activity {
- ImageView image;
- Button start;
- Button cancel;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- image = (ImageView) findViewById(R.id.main_img);
- start = (Button) findViewById(R.id.main_start);
- cancel = (Button) findViewById(R.id.main_cancel);
- final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
- Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- animation.setDuration(2000);
- start.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- image.setAnimation(animation);
- animation.startNow();
- }
- });
- cancel.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- animation.cancel();
- }
- });
- }
- }
- 本节讲解RotateAnimation 动画,
- RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
- 参数说明:
- float fromDegrees:旋转的开始角度。
- float toDegrees:旋转的结束角度。
- int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
- float pivotXValue:X坐标的伸缩值。
- int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
- float pivotYValue:Y坐标的伸缩值。
- 代码:
- <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code17269" class="codebody">
- public class MainActivity extends Activity {
- ImageView image;
- Button start;
- Button cancel;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- image = (ImageView) findViewById(R.id.main_img);
- start = (Button) findViewById(R.id.main_start);
- cancel = (Button) findViewById(R.id.main_cancel);
- final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
- 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
- animation.setDuration(3000);
- start.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- image.setAnimation(animation);
- animation.startNow();
- }
- });
- cancel.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- animation.cancel();
- }
- });
- }
- } </div>
- 本节讲解TranslateAnimation动画,TranslateAnimation比较常用,比如QQ,网易新闻菜单条的动画,就可以用TranslateAnimation实现,
- 通过TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 来定义动画
-
- 参数说明:
- <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code3207" class="codebody">
- float fromXDelta 动画开始的点离当前View X坐标上的差值
- float toXDelta 动画结束的点离当前View X坐标上的差值
- float fromYDelta 动画开始的点离当前View Y坐标上的差值
- float toYDelta 动画开始的点离当前View Y坐标上的差值
- </div>
- 常用方法:
- <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code94921" class="codebody">
- animation.setDuration(long durationMillis);
- animation.setRepeatCount(int i);
- animation.setRepeatMode(Animation.REVERSE);
- </div>
- Xml属性:
- <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code72894" class="codebody">
- android:duration:运行动画的时间
- android:repeatCount:定义动画重复的时间
- </div>
- 代码:
- <div class="codetitle"><span style="CURSOR: pointer"><u>复制代码</u></span> 代码如下:</div><div id="code12415" class="codebody">
- public class MainActivity extends Activity {
- ImageView image;
- Button start;
- Button cancel;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- image = (ImageView) findViewById(R.id.main_img);
- start = (Button) findViewById(R.id.main_start);
- cancel = (Button) findViewById(R.id.main_cancel);
- final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0);
- animation.setDuration(2000);
- animation.setRepeatCount(2);
- animation.setRepeatMode(Animation.REVERSE);
- start.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- image.setAnimation(animation);
- animation.startNow();
- }
- });
- cancel.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- animation.cancel();
- }
- });
- }
- } </div><div class="codebody"> </div><div class="codebody"> </div><div class="codebody"> </div><div class="codebody"> </div>
- <pre code_snippet_id="94243" snippet_file_name="blog_20131203_1_5890611" class="java" name="code">本节讲解AlphaAnimation 动画,窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation。
- 直接看代码:
- 复制代码 代码如下:
- public class MainActivity extends Activity {
- ImageView image;
- Button start;
- Button cancel;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- image = (ImageView) findViewById(R.id.main_img);
- start = (Button) findViewById(R.id.main_start);
- cancel = (Button) findViewById(R.id.main_cancel);
- final AlphaAnimation animation = new AlphaAnimation(1, 0);
- animation.setDuration(2000);
- start.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- image.setAnimation(animation);
- animation.startNow();
- }
- });
- cancel.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- animation.cancel();
- }
- });
- }
- }</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>
- <pre></pre>
- <p></p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <pre></pre>
-
-
相关阅读:
HDU_5688
微服务的一致性问题
我来博客园啦
异常:This application has no explicit mapping for /error, so you are seeing this as a fallback.
异常:Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException
异常:Unknown lifecycle phase "mvn". You must specify a valid lifecycle
SpringMVC中遇到页面跳转出现404错误的问题
Could not resolve view with name '***' in servlet with name 'dispatcher'
关于Could not resolve dependencies for project
让我们相互交流
-
原文地址:https://www.cnblogs.com/wangfeng520/p/5006964.html
Copyright © 2020-2023
润新知