活动显示Toast但不显示动画

时间:2013-10-22 19:14:31

标签: java android animation android-animation

我有以下代码:

private Runnable task = new Runnable() { 
    public void run() {
        Toast.makeText(getApplicationContext(), "Spinner complete!", Toast.LENGTH_LONG).show();
        animationFadeIn = AnimationUtils.loadAnimation(MyPhone.this, R.anim.right_slide_in);
        animationFadeIn.setFillAfter(true);
        tB.setAnimation(animationFadeIn);
    }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myphone);
    TextView tB = (TextView) findViewById(R.id.tvBrandName);

    Handler handler = new Handler();
    handler.postDelayed(task, 3000);
}

我的XML(代码的一部分):

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:id="@+id/llBrand"
    android:weightSum="2"
    android:layout_weight="1"
    android:gravity="center"
    android:background="@drawable/myphoneborder" >
    <TextView
        android:id="@+id/tvBrandName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text=""
        android:layout_weight="1"
        android:textSize="@dimen/phone_text_size"
        android:textStyle="bold"
        android:textColor="#395AFF"
        android:visibility="invisible" />
</LinearLayout>

slide_in动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:fromXDelta="100%p"
        android:toXDelta="0"
        android:duration="700"
    />
</set>

我要做的是,等待活动加载并等待3秒,然后显示ToastAnimationToast工作正常,但动画永远不会显示。知道为什么吗?

1 个答案:

答案 0 :(得分:1)

您启动动画而不是setAnimation。

tB.startAnimation(animationFadeIn);