在android中的textview动画

时间:2015-08-13 09:58:09

标签: android-animation

我希望以一种水平和垂直方式与显示器碰撞的方式为textview设置动画,同时改变文本的随机颜色并运行infinte.is有什么方法?     我试过像

Animation a = AnimationUtils.loadAnimation(this, R.anim.anim);
            a.setFillAfter(true);
            a.reset();
                tv.startAnimation(a);

我得到了解决方案.... 我的解决方案

textview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:id="@+id/layout">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helo suni" />

</LinearLayout>

只需在创建中调用重复功能..

private void repeat() {
        // TODO Auto-generated method stub
        if (curAnimation == 1) {
            animation1 = new TranslateAnimation(width / 2, width, 0, height / 2);
            animation1.setDuration(800);
        } else if (curAnimation == 2) {
            animation1 = new TranslateAnimation(width, width / 2, height / 2, height);
            animation1.setDuration(800);
        }
        else if (curAnimation == 3) {
            animation1 = new TranslateAnimation(width / 2, 0, height, height / 2);
            animation1.setDuration(800);
        }
        else if (curAnimation == 4) {
            animation1 = new TranslateAnimation(0,width/2,height/2,0);
            animation1.setDuration(800);
        }
        animation1.setFillAfter(true);
        Random rnd = new Random();
        int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),
                rnd.nextInt(256));
        tv.setTextColor(color);
        tv.startAnimation(animation1);
        animation1.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // TODO Auto-generated method stub
                if (curAnimation == 4)
                    curAnimation = 1;
                else
                    curAnimation++;
                repeat();
            }
        });

    }

0 个答案:

没有答案