【发布时间】:2015-06-09 21:15:41
【问题描述】:
按照此处的指南进行操作:https://stackoverflow.com/a/5090470/512998 我已经成功地为我的 imageView 实现了淡入淡出动画。然而,imageView 最初是可见的,当动画开始时它只是闪烁变为不可见(alpha=0.0)并慢慢淡入回 alpha=1.0。这里的问题是,我如何设置 imageView 最初是不可见的?
我尝试将 xml 布局中的可见性更改为 INVISIBLE 和 GONE 但动画不起作用。它会在最终结果中显示为空白 imageView。
我也尝试在 xml 布局中更改 imageView 的 alpha 级别,但结果动画很奇怪,因为它适用于我配置的 alpha 级别之上。例如,如果我将 alpha 级别设置为 0.3,动画将在 0.0 到 0.3 之间渐变。如果我将它设置为 0.0,它看起来就像没有动画并且最后不显示图像。
这是我的代码的 sn-p:
anim/fade_in_view.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000"
android:repeatCount="0" />
</set>
layout/activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >
<ImageView
android:id="@+id/imgCharacter"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imgLogo"
android:src="@drawable/darth_vader" />
</RelativeLayout>
src/MainActivity.java
protected void onCreate(Bundle savedInstanceState)
{
...
imageView = (ImageView) findViewById(R.id.imgCharacter);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
Animation fadeInAnimation = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.fade_in_view);
imageView.startAnimation(fadeInAnimation);
}
}, 1000);
}
【问题讨论】:
-
检查加载的布尔值是否为真??
-
忽略加载的上下文,因为该变量用于在加载后播放声音池中的声音
-
@pskink,谢谢!它通过将其切换到 ObjectAnimator 来工作。仅当您可以将其发布为答案并且我会接受时:)
标签: android animation imageview