3

私はAndroidモバイルで見ました。フォトギャラリーをクリックすると、1つの画像が開き(フェードイン)、クリックすると消えます(フェードアウト)。

同じように、私は自分のアプリで行いました。Drawableに1枚の画像を貼り付けました。そして、フェードインとフェードアウトの条件を適用しました。しかし、私は空色の背景よりも画像を見たことがありません。それがビューです。

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

および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>

および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>

このアニメーションを画像ビューで使用してみてください。

于 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 に答える