制作一个平滑的淡出为ImageView的android系统 [英] Making a smooth fade out for imageview in android
本文介绍了制作一个平滑的淡出为ImageView的android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我管理10秒(在我的mainActivity教程图片)后,使ImageView的dissapear。但我想确保平稳淡出,因为这样它不`吨好看,任何人都可以参考我的任何好的教程
I managed to make the imageView dissapear after 10 seconds(a tutorial image on my mainActivity). But i want to make a smooth fade out because like this it doesn`t look good, can anyone refer me to any good tutorial
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
here is the image view 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>
推荐答案
在code换上img.setVisibility(View.GONE)通过调用fadeOutAndHideImage(IMG),其定义是这样的:
Replace img.setVisibility(View.GONE) in your code with a call to fadeOutAndHideImage(img) which is defined like this:
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);
}
这将首先应用淡出动画,然后将隐藏图像视图。
It will apply the fade out animation first, then will hide the image view.
这篇关于制作一个平滑的淡出为ImageView的android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文