我设法使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); }
首先应用淡出动画,然后隐藏图像视图.