我有以下代码:
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>
我想做的是,等待 Activity 加载并等待 3 秒,然后显示 Toast
和 Animation
。 Toast
工作正常,但动画从不显示。知道为什么吗?
最佳答案
您开始动画而不是设置动画。
tB.startAnimation(animationFadeIn);
关于java - Activity 显示 Toast 但不显示动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19526360/