【发布时间】:2018-01-15 22:24:33
【问题描述】:
我正在尝试编写自己的 Toast 类实现。
toast_layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="@android:drawable/toast_frame"
android:layout_gravity="center">
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="This is a toast!" />
</LinearLayout>
然后我尝试淡入淡出它:
LayoutInflater inflater = this.getLayoutInflater();
View toast = inflater.inflate(R.layout.toast_layout,
(ViewGroup) this.findViewById(R.id.toast_layout_root));
long fade_duration = 1000; // milliseconds
AlphaAnimation fadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
fadeInAnimation.setDuration(fade_duration);
toast.startAnimation(fadeInAnimation);
AlphaAnimation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
fadeOutAnimation.setDuration(fade_duration);
fadeOutAnimation.setStartOffset(fade_duration + Toast.LENGTH_LONG);
toast.setAnimation(fadeOutAnimation);
但是然后什么都没有出现。我做错了什么?
感谢您的回复。
【问题讨论】:
-
你的 toast.show() 在哪里?
-
@slymnozdmrc 我不使用 Toast 类。我只是创建视图并淡化它。
标签: android animation alpha fading