私は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"/>