Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android活动屏幕上进行图像淡入淡出?_Android_Image Processing_Fadein - Fatal编程技术网

如何在Android活动屏幕上进行图像淡入淡出?

如何在Android活动屏幕上进行图像淡入淡出?,android,image-processing,fadein,Android,Image Processing,Fadein,我想在Android活动屏幕上显示一张照片,从浅色单调的深褐色渐变到最终的全色。我知道如何在Java Image/BuffereImage上为图形对象执行此操作,但不幸的是,我对Android编程环境一无所知。有人能帮忙吗?一种方法是使用动画集。看这里 我做过的一些示例代码(本例中为无限循环淡出) 在animation.xml文件中 <alpha android:fromAlpha="1.0" android:toAlpha="0.3" android:

我想在Android活动屏幕上显示一张照片,从浅色单调的深褐色渐变到最终的全色。我知道如何在Java Image/BuffereImage上为图形对象执行此操作,但不幸的是,我对Android编程环境一无所知。有人能帮忙吗?

一种方法是使用动画集。看这里

我做过的一些示例代码(本例中为无限循环淡出)

在animation.xml文件中

<alpha android:fromAlpha="1.0" 
       android:toAlpha="0.3"  
       android:duration="7000"
       android:repeatMode="restart"
       android:repeatCount="infinite"/>

您可以从深褐色背景/图片淡入任何您想要的颜色…

Hi Hiro Shi您可以在淡入时执行以下操作:

  ImageView myImageView= (ImageView)findViewById(R.id.myImageView);
  Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
  myImageView.startAnimation(myFadeInAnimation); //Set animation to your ImageView
并在res\anim\文件夹中保存动画文件fadein.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <alpha 
            android:fromAlpha="0.0" 
            android:toAlpha="1.0"
            android:interpolator="@android:anim/accelerate_interpolator"
            android:duration="3000"/>
</set>

我希望图像从完全不透明度单击到0后褪色(然后消失)。我是这样做的:

Animation a = new AlphaAnimation(1.00f, 0.00f);

a.setDuration(1000);
a.setAnimationListener(new AnimationListener() {

    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }

    public void onAnimationEnd(Animation animation) {
        yourView.setVisibility(View.GONE);

    }
});

yourView.startAnimation(a);

另一个简单得多的解决方案是,只需将存根onClick方法添加到要淡入淡出的ImageView中,然后在该方法中添加以下内容:

view.animate().alpha(0).setDuration(2000);      

/* Alpha attribute translates to opacity. 
A solid View means that the alpha attribute is set to 1 (which is the 
default) and completely invisible is 0 */

谢谢Jorge和Mike。我会试试你的方法,很好用。您可能不需要android:repeatCount=“infinite”
,不过……感谢这帮我在recyclerview中制作了一个动画
view.animate().alpha(0).setDuration(2000);      

/* Alpha attribute translates to opacity. 
A solid View means that the alpha attribute is set to 1 (which is the 
default) and completely invisible is 0 */