不断渐变的背景色

前端之家收集整理的这篇文章主要介绍了不断渐变的背景色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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();
        }
    }
}
原文链接:https://www.f2er.com/xml/295129.html

猜你在找的XML相关文章