ValueAnimator的使用
来源:互联网 发布:淘宝网的购物车存在哪 编辑:程序博客网 时间:2024/06/14 00:20
ValueAnimator的使用
activity_main.xml文件中
<RelativeLayout 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"tools:context="www.weshared.anim.MainActivity"> <TextView android:id="@+id/tv" android:background="@android:color/holo_blue_bright" android:padding="16dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> <Button android:id="@+id/btn" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:background="@android:color/holo_red_dark" android:text="执行动画" android:layout_height="wrap_content" /></RelativeLayout>
在res/animator目录下的value_animator.xml文件中(ValueAnimator的xml动画)
<?xml version="1.0" encoding="utf-8"?><animator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:interpolator="@android:interpolator/bounce" android:valueFrom="0px" android:valueTo="720px" android:valueType="intType" />
在MainActicity中
public class MainActivity extends AppCompatActivity implements View.OnClickListener, ValueAnimator.AnimatorUpdateListener { private TextView mTextView; private Button mButton; private int widthPixels; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (TextView) findViewById(R.id.tv); mButton = (Button) findViewById(R.id.btn); mButton.setOnClickListener(this); //获取屏幕的宽度 widthPixels = getResources().getDisplayMetrics().widthPixels; } @Override public void onClick(View v) { //initAnim(); initOfObject(); //initXmlAnim(); } private void initOfObject() { ValueAnimator animator = ValueAnimator.ofObject(new CharEvaluator(), new Character('A'), new Character('Z')); animator.setDuration(2000).start(); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { char animatedValue = (char) animation.getAnimatedValue(); mTextView.setText(String.valueOf(animatedValue)); mTextView.requestLayout(); } }); } private void initAnim() { ValueAnimator animator = ValueAnimator.ofInt(0, widthPixels); animator.setDuration(2000); animator.setInterpolator(new BounceInterpolator()); animator.start(); animator.addUpdateListener(this); } private void initXmlAnim() { ValueAnimator animator = (ValueAnimator) AnimatorInflater.loadAnimator(this, R.animator.value_animator); animator.start(); animator.addUpdateListener(this); } @Override public void onAnimationUpdate(ValueAnimator animation) { int animatedValue = (int) animation.getAnimatedValue(); mTextView.setWidth(animatedValue); mTextView.setHeight((int) (animatedValue * 0.6)); mButton.setHeight((int) (animatedValue * 0.6)); mTextView.requestLayout(); mButton.requestLayout(); } public class CharEvaluator implements TypeEvaluator<Character> { @Override public Character evaluate(float fraction, Character startValue, Character endValue) { int startInt = (int) startValue; int endInt = (int) endValue; int curInt = (int) (startInt + fraction * (endInt - startInt)); char result = (char) curInt; return result; } }}
0 0
- ValueAnimator的使用
- ValueAnimator.ofObject的使用
- ValueAnimator的使用
- Android:ValueAnimator的使用举例
- ValueAnimator的介绍与使用
- ValueAnimator及ObjectAnimator的使用
- Android中ValueAnimator的使用
- ValueAnimator和TypeEvaluator 的使用
- 属性动画ValueAnimator和ObjectAnimator的使用
- 使用ValueAnimator制作两款可伸展的动画
- ValueAnimator和自定义Interpolator的配合使用
- ValueAnimator的简单介绍和使用
- ValueAnimator的初步使用(动画属性)
- 三、ValueAnimator属性动画的基本使用
- 使用ValueAnimator设置动画
- ValueAnimator高级使用之一
- Android使用ValueAnimator实现双击事件的判断
- Android 属性动画valueAnimator和objectAnimator的使用
- poj 3274 哈希查找(黄金平衡)
- [Lintcode]Valid Parentheses
- 338. Counting Bits
- Spring 注解总结
- KindEditor编辑器的使用
- ValueAnimator的使用
- PLSQL Developer连接数据库报错ora-12514解决
- maven---私服
- 算法题之查找第一个只出现一次的字符
- 练习005
- Android APP头像的图标与背景的设置
- 仿Google应用动态隐藏显示状态栏
- 亚马逊AWS免费套餐EC2安装centos连接登录并创建root
- Hdu 5120 Intersection【计算圆环相交面积】