Android Animation(三)
来源:互联网 发布:查看阿里云ecs数据库 编辑:程序博客网 时间:2024/05/16 19:27
之前编写的一些动画,翻转,平移都是各自独立的,下面我们编写一个混合的,并且我也同时编写了利用xml和java的代码的方案。
跟之前一样,首先在res下创建一个anim文件夹,创建一个xml文件
1.animone.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:shareInterpolator="true"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:startOffset="500" android:duration="500"/> <translate android:fromXDelta="0%" android:toXDelta="100%" android:fromYDelta="0%" android:toYDelta="100%" android:duration="2000"/></set>
<?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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="sc.animationthird.MainActivity"> <ImageView android:id="@+id/image_view" android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"/> <Button android:layout_marginTop="100dp" android:id="@+id/btn_start_xml" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动动画xml" android:layout_gravity="center_horizontal"/> <Button android:id="@+id/btn_start_java" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动动画java" android:layout_gravity="center_horizontal"/></LinearLayout>
public class MainActivity extends AppCompatActivity { private ImageView imageView; private Button btnStartXml; private Button btnStartJava; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.image_view); btnStartXml = (Button) findViewById(R.id.btn_start_xml); btnStartJava = (Button) findViewById(R.id.btn_start_java); btnStartXml.setOnClickListener(new XmlListener()); btnStartJava.setOnClickListener(new JavaListener()); } class XmlListener implements View.OnClickListener{ @Override public void onClick(View v) { Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.animone); imageView.startAnimation(animation); } } class JavaListener implements View.OnClickListener{ @Override public void onClick(View v) { AnimationSet animationSet = new AnimationSet(true); ScaleAnimation scaleAnimation = new ScaleAnimation(0,0.1f,0,0.1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); RotateAnimation rotateAnimation = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); rotateAnimation.setDuration(1000); animationSet.addAnimation(rotateAnimation); animationSet.addAnimation(scaleAnimation); imageView.startAnimation(animationSet); } }}
0 0
- Android Animation(三)
- 【Android】Animation(三)
- Android属性动画---Property Animation(三)
- Android动画之Property Animation(三)
- Android学习之Animation(三)
- Android三种动画View Animation(补间动画) 、Drawable Animation(帧动画) 、Property Animation(属性动画)(上)
- Android三种动画View Animation(补间动画) 、Drawable Animation(帧动画) 、Property Animation(属性动画)(下)
- Android应用资源---动画资源(Animation Resources)(三)
- Android动画之属性动画(Property Animation)(三)
- Android动画(三)之属性动画(Property Animation)
- Android动画学习总结(三)------- property animation
- Android动画学习-Animation动画总述(三)
- Android动画之三:Property Animation 完全解析 (上)
- android动画实现-Tween animation(三)
- Android 动画系列三:Propety Animation
- Android动画之三:Property Animation(上)
- Android动画三:属性动画 (property animation)
- Animation Android ( 一)
- Python 字符串格式化
- Android 生成差分包
- webpack笔记----开发环境
- ubuntu broadcom驱动无法正常工作
- 欢迎使用CSDN-markdown编辑器
- Android Animation(三)
- 使用zsh的十大优点
- Xunsearch搭建及使用
- spring cloud-构建微服务架构的网关(API GateWay)
- iOS获取键盘弹出高度,监听键盘弹出退出
- 六、AngularJS 之事件指令
- android实现点击2下退出程序
- 一摞烙饼
- datatable search 里的input中的placeholder效果代码