Android开发-自定义View-AndroidStudio(四)简介动画
来源:互联网 发布:it技术分类 编辑:程序博客网 时间:2024/05/21 07:47
转载请注明出处:http://blog.csdn.net/iwanghang/article/details/53738561
绝对博文有用,请点赞,请留言,谢谢!~
直接看GIF效果和代码:
MainActivity.java:
转载请注明出处:http://blog.csdn.net/iwanghang/article/details/53738561
绝对博文有用,请点赞,请留言,谢谢!~
绝对博文有用,请点赞,请留言,谢谢!~
直接看GIF效果和代码:
MainActivity.java:
package com.iwanghang.propertyanimation;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.view.View;import android.view.animation.TranslateAnimation;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity { private ImageView iv_animation; private TextView tv_animation_msg; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv_animation = (ImageView) findViewById(R.id.iv_animation); iv_animation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "点击了图片", Toast.LENGTH_SHORT).show(); } }); } /** * 补间(视图)动画 */ public void testTweenAnimation(View v) { // 由左上向右下移动 TranslateAnimation animation = new TranslateAnimation(0, iv_animation.getWidth(), 0, iv_animation.getHeight()); // 由右下向左上移动 //TranslateAnimation animation = new TranslateAnimation(iv_animation.getWidth(), 0, iv_animation.getHeight(), 0); animation.setDuration(3000); // 设置持续时间 animation.setFillAfter(true); // 界面会停留在动画播放完时的界面 iv_animation.startAnimation(animation); // 运行动画 } /** * 属性动画 */ public void testPropertyAnimation(View v) { ObjectAnimator animator3 = ObjectAnimator.ofFloat(iv_animation,"translationX",0,iv_animation.getWidth()); ObjectAnimator animator4 = ObjectAnimator.ofFloat(iv_animation,"translationY",0,iv_animation.getHeight()); /** * TranslateAnimation 补间动画 一个动画 * AnimatorSet + playTogether 属性动画 两个动画一起播放 */ AnimatorSet set = new AnimatorSet(); set.playTogether(animator3,animator4); set.setDuration(2000); set.start();// ObjectAnimator animator = ObjectAnimator.ofFloat(iv_animation, "translationX", 0,iv_animation.getWidth());// ObjectAnimator animator2 = ObjectAnimator.ofFloat(iv_animation, "translationY", 0,iv_animation.getHeight());// AnimatorSet animatorSet = new AnimatorSet();// animatorSet.setDuration(2000);// animatorSet.setInterpolator(new BounceInterpolator());// //两个动画一起播放// animatorSet.playTogether(animator, animator2);// //开始播放// animatorSet.start();// //另外一种写法// iv_animation.animate()// .translationXBy(iv_animation.getWidth())// .translationYBy(iv_animation.getWidth())// .setDuration(2000)// .setInterpolator(new BounceInterpolator())// .start(); } public void reset(View v) { iv_animation.clearAnimation(); }}activity_main.xml:
<?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" tools:context="com.iwanghang.propertyanimation.MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="testTweenAnimation" android:text="测试补间(视图)动画" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="testPropertyAnimation" android:text="测试属性动画" /> <!--我是分割--> <ImageView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#000000" /> <TextView android:textColor="#000000" android:text="补间动画可以被clearAnimation,属性动画不可以 因为属性动画没有setFillAfter属性" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="reset" android:text="重置补间动画" /> <ImageView android:id="@+id/iv_animation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/logo" /> <!--我是分割--> <ImageView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#000000" /></LinearLayout>
转载请注明出处:http://blog.csdn.net/iwanghang/article/details/53738561
欢迎移动开发爱好者交流
沈阳或周边城市公司有意开发Android,请与我联系
联系方式
微信:iwanghang
QQ:413711276
邮箱:iwanghang@qq.com
沈阳或周边城市公司有意开发Android,请与我联系
联系方式
微信:iwanghang
QQ:413711276
邮箱:iwanghang@qq.com
绝对博文有用,请点赞,请留言,谢谢!~
1 0
- Android开发-自定义View-AndroidStudio(四)简介动画
- Android开发-自定义View-AndroidStudio(一)
- Android开发-自定义View-AndroidStudio(七)popupwindow
- Android开发-自定义View-AndroidStudio(十九)HackView
- Android开发-自定义View-AndroidStudio(八)自定义View初体验
- Android开发-自定义View-AndroidStudio(二十七)移动的View
- Android开发-自定义View-AndroidStudio(二十八)缩放的View
- Android开发-自定义View-AndroidStudio(十七)自定义水波纹(1)
- Android开发-自定义View-AndroidStudio(十八)自定义水波纹(2)
- Android开发-RecyclerView-AndroidStudio(四)属性动画(1)RemoveDuration
- Android开发-自定义View-AndroidStudio(三)扇形多级菜单
- Android开发-自定义View-AndroidStudio(五)ViewPager初体验
- Android开发-自定义View-AndroidStudio(六)ViewPager再体验
- Android开发-自定义View-AndroidStudio(九)手势监听类GestureDetector
- Android开发-自定义View-AndroidStudio(十)仿ViewPager(1)
- Android开发-自定义View-AndroidStudio(十一)有趣的BUG
- Android开发-自定义View-AndroidStudio(十二)仿ViewPager(2)
- Android开发-自定义View-AndroidStudio(十三)仿ViewPager(3)
- PostgreSQL学习篇9.6 数学函数和操作符
- 网站安全之几种常见的网络攻击方式
- awk实现数据库查询功能
- good website
- iOS开发 跳转到指定界面(栈中不存在的界面)
- Android开发-自定义View-AndroidStudio(四)简介动画
- 【Android】Anroid5.0+新控件---酷炫标题栏的简单学习
- DOS命令之断开本机远程连接BAT
- node环境下,jsdoc使用方法简介
- Fresco图片加载框架使用方法完全指南
- 使用easyui dialog 弹出框的一些注意事项
- OFFICE 2007下右键新建OFFICE 2003的快捷方式
- Android Studio 百度地图 230错误 Scode码校验失败应急处理 只看楼主收藏回复
- VGG Convolutional Neural Networks Practical(3)pooling