动画的简单应用
2016-10-12 18:05
330 查看
红点代表pointx,pointy分别是0,0
rotate,scale 的属性
android:pivotX=”0%”
android:pivotY=”0%”
都在红点出发生变化
动画的基本用法:
package com.example.animation; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private Button scale; private Button alpha; private Button rotate; private Button translate; private ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); scale = (Button) findViewById(R.id.scale); alpha =(Button) findViewById(R.id.alpha); rotate =(Button)findViewById(R.id.rotate); translate = (Button) findViewById(R.id.translate); translate.setOnClickListener(this); rotate.setOnClickListener(this); alpha.setOnClickListener(this); scale.setOnClickListener(this); image = (ImageView) findViewById(R.id.image); } @Override public void onClick(View v) { Animation loadAnimation; switch (v.getId()){ case R.id.scale: { loadAnimation = AnimationUtils.loadAnimation(this, R.anim.scale); image.startAnimation(loadAnimation); break; } case R.id.alpha: { loadAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha); image.startAnimation(loadAnimation); break; } case R.id.rotate: { loadAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate); image.startAnimation(loadAnimation); break; } case R.id.translate: { loadAnimation = AnimationUtils.loadAnimation(this, R.anim.translate); image.startAnimation(loadAnimation); break; } } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/scale" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="ScaleAnimation(缩放动画)" /> <Button android:id="@+id/alpha" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="AlphaAnimation(透明度动画)" /> <Button android:id="@+id/rotate" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="RotateAnimation(旋转动画)" /> <Button android:id="@+id/translate" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TranslateAnimation(位移动画)" /> <ImageView android:id="@+id/image" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:src="@mipmap/ic_launcher" > </ImageView> </LinearLayout>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1000" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="100" android:toYDelta="100" /> </set>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate android:duration="1000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="0%" android:pivotY="0%" android:toDegrees="+360" /> </set>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="1000" android:fromAlpha="0.1" android:toAlpha="1.0" > </alpha> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <scale b660 android:duration="2000" android:fillAfter="false" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="0%" android:pivotY="0%" android:toXScale="1.0" android:toYScale="1.0" /> <!--pivotX,pivotY相对于x,y周的位置 50%,50% 为中心--> </set>
相关文章推荐
- Unity的简单贴图动画的应用
- android studio开发Activity切换动画以及ButterKnife注解简单应用
- java回调函数的应用,andriod简单2d动画显示!
- Android布局动画简单应用
- Android属性动画应用超简单代码打造酷炫扇形(卫星),圆形菜单
- CSS3动画简单应用
- Anroid动画总结一:属性动画(Property)简单应用
- swiper 3出来了,还有动画,做场景应用更简单了
- iOS动画 过渡/转场动画的简单应用
- 属性动画简单应用
- IOS的几种动画及其简单应用
- 前端动画渲染引擎pixi.js系列(1)简单介绍及应用
- 学习OpenGL(二)应用OpenGL和GLUT制作简单动画
- CALayer简单应用——隐式动画
- PhotoShop制作简单的文字动画--多媒体技术与应用
- Android属性动画应用超简单代码打造酷炫扇形(卫星),圆形菜单
- 透明网关ProxyARP在APN上的简单应用
- Tomcat4/5连接池的设置及简单应用示例
- SQLSERVER扩展存储过程XP_CMDSHELL的简单应用