3

我在安卓手机上见过。当我单击照片库时,会打开一个图像(淡入),然后单击消失(淡出)。

同样,我已经在我的应用程序中完成了。我在 Drawable 中粘贴了一张图片。并应用了淡入淡出条件。但我没有看到比天蓝色背景的任何图像。那就是看法。

我如何在 Android 中以编程方式执行此操作?

我可以通过什么方式解决这个问题?我在这里犯了什么错误?

我的代码是:

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);
        }
    }
} );



} }

然后在 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"/>
4

2 回答 2

2

对于淡入淡出.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>

对于淡出.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>

尝试在您的图像视图中使用此动画..

于 2012-09-05T07:02:34.877 回答
1

这对我有用:

淡入-

<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
        android:duration="1000" />
</set>

消退-

<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
        android:duration="1000" />
</set>
于 2013-06-14T09:55:04.273 回答