我设法让 imageView 在 10 秒后消失(我的 mainActivity 上的教程图片)。但是我想做一个平滑的淡出,因为这样看起来不太好,任何人都可以向我推荐任何好的教程
img=(ImageView)findViewById(R.id.ImageTutorial);
if(getIntent()!=null)
{
Bundle extras = getIntent().getExtras();
String TutorialDemo=extras !=null? extras.getString("TutorialDemo"):"false";
if(TutorialDemo.equals("true"))
{
Runnable mRunnable;
Handler mHandler=new Handler();
mRunnable=new Runnable() {
@Override
public void run() {
img.setVisibility(View.GONE); //This will remove the View. and free s the space occupied by the View
}
};
mHandler.postDelayed(mRunnable,10*900);
}
else
{
img.setVisibility(View.GONE);
}
}
这是 ImageView xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fullview"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical" >
.
.
.
.
<ImageView
android:contentDescription="tutorial"
android:id="@+id/ImageTutorial"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:background="@drawable/tutorial"
android:layout_marginTop="40dp"
android:gravity="center"
/>
</LinearLayout>
最佳答案
将代码中的 img.setVisibility(View.GONE) 替换为对 fadeOutAndHideImage(img) 的调用,其定义如下:
private void fadeOutAndHideImage(final ImageView img)
{
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(1000);
fadeOut.setAnimationListener(new AnimationListener()
{
public void onAnimationEnd(Animation animation)
{
img.setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationStart(Animation animation) {}
});
img.startAnimation(fadeOut);
}
它会先应用淡出动画,然后隐藏 ImageView 。
关于android - 在android中为imageview平滑淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20782260/