动画Animation
2016-05-17 20:08
155 查看
public class MainActivity extends Activity { private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); } // 透明动画 public void alpha(View v) { AlphaAnimation aa = new AlphaAnimation(1.0f, 0.0f); // 设置动画的时长 aa.setDuration(3000); // 设置播放重复次数 aa.setRepeatCount(2); // reverse反向 restart正向 aa.setRepeatCount(Animation.REVERSE); iv.startAnimation(aa); } /** * 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 void scale(View v) { ScaleAnimation sa = new ScaleAnimation(0, 1.0f, 0, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); sa.setDuration(3000); sa.setRepeatCount(2); sa.setRepeatMode(Animation.REVERSE); iv.startAnimation(sa); } /** * fromXType 起始点X坐标相对于自身还是相对于父控件 fromXValue X坐标上的起始位置 toXType 终点X坐标相对于自身还是相对于父控件 toXValue X坐标上的终点位置 fromYType 起始点Y坐标相对于自身还是相对于父控件 fromYValue Y坐标上的起始位置 toYType 终点Y坐标相对于自身还是相对于父控件 toYValue Y坐标上的终点位置 */ //位移动画 public void trans(View v){ TranslateAnimation ta=new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.5f); ta.setDuration(3000); ta.setRepeatCount(4); ta.setRepeatMode(Animation.REVERSE); iv.startAnimation(ta); } //旋转动画 public void rotate(View v) { RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 1.0f); ra.setDuration(3000); ra.setRepeatCount(3); ra.setRepeatMode(Animation.REVERSE); iv.startAnimation(ra); } }
相关文章推荐
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
- 做事必备9种能力、9种手段、9种心态分享
- 集成友盟分享 分享成功后iOS8回调方法正常 iOS9没有回调
- Socket编程------模拟QQ聊天(TCP)
- HDU 1022 Train Problem I (STL 栈模拟)
- 分子量(UVa1586)
- hdu_4828_Grids(卡特兰数+逆元)
- 作业八
- windows程序是如何开始执行的??
- bzoj3575: [Hnoi2014]道路堵塞
- HDU 1044 bfs+dfs
- Ptmind 遇见最好的你!
- 札记-ryu l3 switch & mapreduce
- Jmeter中的几个重要测试指标释义
- 基于SpringMVC的RESTful API设计
- bzoj 3931(spfa+最大流)
- CoreData多线程安全
- css float left right 中间空间城数据无法显示
- 大型网站架构系列:负载均衡详解(上)
- Unity3D-NavMesh导航网格寻路