我发现了一个奇怪的情况。下面的animation.xml
不起作用。 ImageView
总是看不见的。
activity.xml
...
<ImageView
android:layout_width="324px"
android:layout_height="90px"
android:alpha="0"
android:src="@drawable/img"
android:id="@+id/img"/>
...
custom_anim.xml(对可见不可见)
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0"/>
main activity.Java
Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.custom_anim);
...
...
((ImageView)getActivity().findViewById(R.id.img)).startAnimation(anim);
但是,如果删除android:alpha
上的行activity.xml
,动画工作。当然,在动画制作之前,ImageView
并不是看不见的,但至少它可以奏效。请让我知道为什么它发生了,我怎么能使动画可以使用线android:alpha
尝试使用下面的代码
((ImageView)getActivity().findViewById(R.id.img)).animate().alpha(1f).setDuration(3000).start();
希望这可以帮助