不断渐变的背景色

1、创建显示的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.ui.demo.custom.AnimatorTestActivity"
    android:id="@+id/container">

</LinearLayout>
2、创建颜色渐变属性
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName = "backgroundColor"
    android:duration="3000"
    android:valueFrom="#FF8080"
    android:valueto="#8080FF"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:valueType="intType">
</objectAnimator>
3、显示的Activity
public class AnimatorTestActivity extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animator_test);
        LinearLayout container = (LinearLayout) findViewById(R.id.container);
        container.addView(new MyAnimationView(this));
    }

    private class MyAnimationView extends View
    {
        public MyAnimationView(Context context)
        {
            super(context);
            //加载动画资源
            ObjectAnimator colorAnim = (ObjectAnimator) AnimatorInflater
                    .loadAnimator(AnimatorTestActivity.this,R.anim.color_anim);
            colorAnim.setEvaluator(new ArgbEvaluator());
            //对该View本身应用属性动画
            colorAnim.setTarget(this);
            colorAnim.start();
        }
    }
}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念