在android中为imageview制作平滑淡出
我设法在10秒钟后使imageView消失(这是关于我主要活动的教程图像)。但是我想做一个平滑的淡出,因为像这样它看起来不太好,有人能给我推荐一些好的教程吗在android中为imageview制作平滑淡出,android,fadeout,Android,Fadeout,我设法在10秒钟后使imageView消失(这是关于我主要活动的教程图像)。但是我想做一个平滑的淡出,因为像这样它看起来不太好,有人能给我推荐一些好的教程吗 img=(ImageView)findViewById(R.id.ImageTutorial); if(getIntent()!=null) { Bundle extras = getIntent().getExtras(); String TutorialDemo=extras
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>
.
.
.
.
从这个代码片段中获取提示。 所需的代码如下所示-
Animation fadeOut = new AlphaAnimation(1, 0); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0)
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(500); // Start fading out after 500 milli seconds
fadeOut.setDuration(1000); // Fadeout duration should be 1000 milli seconds
现在将其设置为元素,例如图像视图-
myImageView.setAnimation(fadeOut);
将代码中的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);
}
它将首先应用淡出动画,然后隐藏图像视图。您可以参考以下链接。这对你会有更大的帮助。。对不起,我的错。它应该是img.startAnimation(淡出),而不是img.setAnimation();请尝试更正代码。