在android中平滑淡出图像视图

我设法使imageView在10秒后消失(我的主动性的教程图像).但是我想要顺利淡出,因为这样看起来不好看,任何人都可以参考任何好的教程
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);
        }
         }

这里是图像视图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);
}

首先应用淡出动画,然后隐藏图像视图.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...