Android布局特效(二)
来源:互联网 发布:双色球绝密算法 编辑:程序博客网 时间:2024/06/05 17:47
public class MainActivity extends Activity {
AlphaAnimation animation_alpha;
RotateAnimation animation_rotate;
ScaleAnimation animation_scale;
TranslateAnimation animation_translate;
AnimationSet animationSet;
ImageView image;
DisplayMetrics displayMetrics;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView)findViewById(R.id.imageview);
// image.setScaleType(ScaleType.FIT_XY);
initAnimation();
}
private void initAnimation() {
displayMetrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//透明度控制动画效果 alpha
animation_alpha=new AlphaAnimation(0.1f,1.0f);
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
animation_alpha.setRepeatCount(-1);//设置循环
animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒
// 旋转效果rotate
animation_rotate = new RotateAnimation(0, -90,
RotateAnimation.RELATIVE_TO_PARENT, 0,
RotateAnimation.RELATIVE_TO_PARENT, 1);
//第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
// animation_rotate.setRepeatCount(-1);
animation_rotate.setDuration(3000);//设置时间持续时间为 5000毫秒
//尺寸伸缩动画效果 scale
animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_scale.setRepeatCount(-1);
animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒
//移动动画效果translate
animation_translate=new TranslateAnimation(0,-300,0,0);
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第三个参数toYDelta为动画结束时Y坐标上的移动位置
// animation_translate.setRepeatCount(-1);//设置动画执行多少次,如果是-1的话就是一直重复
animation_translate.setDuration(3000);//设置时间持续时间为 5000毫秒
animationSet=new AnimationSet(true);
// animationSet.addAnimation(animation_alpha);//透明度
animationSet.addAnimation(animation_rotate);//旋转
// animationSet.addAnimation(animation_scale);//尺寸伸缩
// animationSet.addAnimation(animation_translate);//移动
image.startAnimation(animationSet);//开始播放
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
AlphaAnimation animation_alpha;
RotateAnimation animation_rotate;
ScaleAnimation animation_scale;
TranslateAnimation animation_translate;
AnimationSet animationSet;
ImageView image;
DisplayMetrics displayMetrics;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView)findViewById(R.id.imageview);
// image.setScaleType(ScaleType.FIT_XY);
initAnimation();
}
private void initAnimation() {
displayMetrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//透明度控制动画效果 alpha
animation_alpha=new AlphaAnimation(0.1f,1.0f);
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
animation_alpha.setRepeatCount(-1);//设置循环
animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒
// 旋转效果rotate
animation_rotate = new RotateAnimation(0, -90,
RotateAnimation.RELATIVE_TO_PARENT, 0,
RotateAnimation.RELATIVE_TO_PARENT, 1);
//第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
// animation_rotate.setRepeatCount(-1);
animation_rotate.setDuration(3000);//设置时间持续时间为 5000毫秒
//尺寸伸缩动画效果 scale
animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_scale.setRepeatCount(-1);
animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒
//移动动画效果translate
animation_translate=new TranslateAnimation(0,-300,0,0);
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第三个参数toYDelta为动画结束时Y坐标上的移动位置
// animation_translate.setRepeatCount(-1);//设置动画执行多少次,如果是-1的话就是一直重复
animation_translate.setDuration(3000);//设置时间持续时间为 5000毫秒
animationSet=new AnimationSet(true);
// animationSet.addAnimation(animation_alpha);//透明度
animationSet.addAnimation(animation_rotate);//旋转
// animationSet.addAnimation(animation_scale);//尺寸伸缩
// animationSet.addAnimation(animation_translate);//移动
image.startAnimation(animationSet);//开始播放
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
0 0
- Android布局特效(二)
- Android布局特效(一)
- Android 特效库 - 下拉刷新(二)
- Android用户界面(二):布局
- Android布局(二)RelativeLayout
- Android的布局(二)
- android高仿微信布局(二)
- Android--常用布局、特效--参考Demo
- Android Animation动画详解(二): 组合动画特效
- Android界面布局二---------------RelativeLayout(相对布局)
- android基础——界面布局(二) 线性布局
- android Activity布局初步(二)- 嵌套布局
- (二)Android布局之相对布局(RelativeLayout)
- Android中的布局方式(二)
- android编程之代码布局(二)
- android编程之代码布局(二)
- android编程之代码布局(二)
- 浅谈Android五大布局(二)
- 【LeetCode-面试算法经典-Java实现】【206-Reverse Linked List(反转一个单链表)】
- [8月]总结
- PS学习笔记-----选区的作用即是:用来控制操作的范围
- Android Api Demos登顶之路(五十一)Notification-->Status Bar
- Spring的 depends-on
- Android布局特效(二)
- 短信里的陌生链接千万不要点! 点了就会中招
- 每天5道面试题(四)java基础
- watch postgres's source code commit
- PS学习笔记-----钢笔工具
- git使用(持续更新)
- 异常值
- 软件考试
- mysql-安装之cmake的编译安装(mysql 5.6以后需要cmake编译安装)