首页 > 其他 > 详细

利用动画实现控件背景色渐变

时间:2014-08-08 15:28:16      阅读:329      评论:0      收藏:0      [点我收藏+]

1.动画文件:

bubuko.com,布布扣
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:propertyName="backgroundColor"
 4     android:duration="5000"
 5     android:valueFrom="#ff0033"
 6     android:valueTo="#000099"
 7     android:repeatCount="infinite"
 8     android:repeatMode="reverse"
 9     android:valueType="intType">
10 </objectAnimator>
View Code

2.类文件:

bubuko.com,布布扣
 1 package com.soft.colorchangingdemo;
 2 
 3 import android.animation.AnimatorInflater;
 4 import android.animation.ArgbEvaluator;
 5 import android.animation.ObjectAnimator;
 6 import android.app.Activity;
 7 import android.content.Context;
 8 import android.os.Bundle;
 9 import android.view.View;
10 import android.widget.RelativeLayout;
11 
12 public class MainActivity extends Activity {
13 
14     @Override
15     protected void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.activity_main);
18         init();
19     }
20 
21     private void init() {
22         RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
23         AnimationView animationView = new AnimationView(this);
24         relativeLayout.addView(animationView);
25     }
26 
27     public class AnimationView extends View {
28         public AnimationView(Context context) {
29             super(context);
30             ObjectAnimator objectAnimator = (ObjectAnimator) AnimatorInflater
31                     .loadAnimator(MainActivity.this, R.anim.coloranimation);
32             objectAnimator.setEvaluator(new ArgbEvaluator());
33             objectAnimator.setTarget(this);
34             objectAnimator.start();
35         }
36 
37     }
38 
39 }
View Code

 

利用动画实现控件背景色渐变,布布扣,bubuko.com

利用动画实现控件背景色渐变

原文:http://www.cnblogs.com/yili-2013/p/3898620.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!