如何使用淡入和淡出与图像效果采用过渡,机器人 [英] How to use fade in and fade out effect with an image using Transition, android

查看:135
本文介绍了如何使用淡入和淡出与图像效果采用过渡,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了Android手机。当我点击图片库,一个图像被打开(淡入)后,我点击消失(淡出)。

一样,我做我的应用程序。我在绘制对象粘贴一个图像。而应用淡入和淡出的条件。但我还没有见过比天蓝色背景的任何图像。这就是视图。

我怎么能做到这一点编程的机器人。

在什么样的方式,我有解决它了这一问题。什么错误,我在这里做。

任何帮助/建议,将不胜AP preciated!

我的code是:

  BTN =(按钮)findViewById(R.id.C​​lick);
   viewToAnimate =(查看)findViewById(R.id.view1);
   btn.setOnClickListener(新View.OnClickListener(){

    @覆盖
    公共无效的onClick(视图v){


        如果(viewToAnimate.getVisibility()== View.VISIBLE)
        {
            布尔toRight = FALSE;
            上下文C = NULL;
            //动画OUT = AnimationUtils.makeOutAnimation(这一点,真正的);
            动画OUT = AnimationUtils.makeOutAnimation(C,toRight);
            viewToAnimate.startAnimation(出);
             viewToAnimate.setVisibility(View.INVISIBLE);

        } 其他 {
          INT标识= 0;
        上下文C = NULL;
        //动画= AnimationUtils.loadAnimation(这一点,android.R.anim.fade_in);
           动画= AnimationUtils.loadAnimation(C,ID);

            viewToAnimate.startAnimation(在);
            viewToAnimate.setVisibility(View.VISIBLE);
        }
    }
});



}}
 

然后main.xml中:

 <按钮
    机器人:ID =@ + ID /点击
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=按钮/>

< ImageView的
    机器人:ID =@ + ID / imageView1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:SRC =@可绘制/淡入淡出/>


<查看
    机器人:ID =@ + ID /厂景
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:后台=#AAA
    机器人:SRC =@可绘制/淡入淡出/>
 

解决方案

有关fadeIn.xml

 < XML版本=1.0编码=UTF-8&GT?;
       <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
         <阿尔法机器人:fromAlpha =0.0的Andr​​oid版本:toAlpha =1.0
          机器人:插=@机器人:动画/ accelerate_interpolator
          机器人:时间=2000/>
     < /集>
 

有关fadeOut.xml

 <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
         <阿尔法机器人:fromAlpha =1.0的Andr​​oid版本:toAlpha =0.0
          机器人:插=@机器人:动画/ accelerate_interpolator
          机器人:时间=2000/>
     < /集>
 

请尝试使用此动画图像视图。

I have seen in Android mobile. When i click photo gallery, one image is opened (Fade in) and after i clicked disappeared (Fade out).

Same, i have done in my app. I have pasted one image in Drawable. And applied Fade in and Fade out conditions. But i have not seen any images than sky blue color background. That is view.

How could i do this programmatically in Android .

In what way i have to fix it out this problem. What mistake i have done here.

Any help/Suggestions would be greatly appreciated !

My code is :

btn=(Button)findViewById(R.id.Click);
   viewToAnimate=(View)findViewById(R.id.view1);
   btn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {


        if(viewToAnimate.getVisibility()==View.VISIBLE)
        {
            boolean toRight = false;
            Context c = null;
            //Animation out=AnimationUtils.makeOutAnimation(this,true);
            Animation out=AnimationUtils.makeOutAnimation(c, toRight);
            viewToAnimate.startAnimation(out);
             viewToAnimate.setVisibility(View.INVISIBLE);

        } else {
          int id = 0;
        Context c = null;
        //  Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
           Animation in=AnimationUtils.loadAnimation(c, id);

            viewToAnimate.startAnimation(in);
            viewToAnimate.setVisibility(View.VISIBLE);
        }
    }
} );



} }

Then in Main.xml :

 <Button
    android:id="@+id/Click"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/fade" />


<View
    android:id="@+id/view1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#AAA" 
    android:src="@drawable/fade"/>

解决方案

for 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="2000"/>
     </set>

for fadeOut.xml

 <set xmlns:android="http://schemas.android.com/apk/res/android">
         <alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
          android:interpolator="@android:anim/accelerate_interpolator" 
          android:duration="2000"/>
     </set>

try using this animation in your image view..

这篇关于如何使用淡入和淡出与图像效果采用过渡,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆