2013-01-21 5 views
0

이 튜토리얼을 찾았습니다 http://android-er.blogspot.com/2012/02/animate-fade-infade-out-by-changing.html 페이드 아웃 같은 이미지 어떻게 두 이미지를 사용하도록이 코드를 변경합니까 페이드 아웃 하나의 이미지 페이드 아웃 두 번째 자동으로 ???페이드 인하는 방법 1 이미지 페이드 아웃 두번째 이미지?

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.Button; 
import android.widget.ImageView; 

public class AndroidAnimTranslateActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    Button buttonFadeOut = (Button)findViewById(R.id.fadeout); 
    final ImageView image = (ImageView)findViewById(R.id.image); 

    Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein); 

    image.startAnimation(animationFadeIn); 
    animationFadeIn.setAnimationListener(new AnimationListener() { 

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

     } 

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

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      // TODO Auto-generated method stub 

      image.startAnimation(animationFadeOut); 

     } 
    }); 
    final Animation animationFadeOut = AnimationUtils.loadAnimation(this, 
R.anim.fadeout); 
    buttonFadeOut.setOnClickListener(new Button.OnClickListener(){ 

     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      image.startAnimation(animationFadeOut); 
     }}); 
} 
} 


     <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 
<Button 
    android:id="@+id/fadein" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Fade In"/> 
<Button 
    android:id="@+id/fadeout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Fade Out"/> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:gravity="center"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout>  

    </LinearLayout> 



     <!-------fadein.xml-->> 


     <?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator"> 
<alpha 
    android:fromAlpha="0.1" 
    android:toAlpha="1.0" 
    android:duration="2000" 
    /> 
    </set> 



<!--------fadeout.xml-----> 


       <?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator"> 
<alpha 
    android:fromAlpha="1.0" 
    android:toAlpha="0.1" 
    android:duration="2000" 
    /> 
</set> 
+0

종료됩니다 동안

image.startAnimation(animationFadeIn); animationFadeIn.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub image.startAnimation(animationFadeOut); } }); 

그래서 두 번째 애니메이션이 시작됩니다. [여기] [1] 당신은 예제를 찾을 수 있습니다. [1] : http://stackoverflow.com/questions/9987839/android-imageswitcher-example – Aram

+0

선언 최종 애니메이션 animationFadeOut = AnimationUtils.loadAnimation (이, R.anim.fadeout); before image.startAnimation (animationFadeOut); –

+0

그리고 난 buttonFadeIn의 onClick을 호출해야한다고 생각합니다 –

답변

0

난 당신이 Animationlistener를 사용한다고 생각 : 먼저 ImageSwitcher를 사용할 수 있습니다

+0

하지만 2 diffrent 이미지가 어떻게 2 imageview이 코드를 구현합니까 ??? –

+0

두 개의 서로 다른 이미지 뷰가있는 경우 image2.startAnimation()을 사용할 수 있습니다. 또는 동일한 이미지 뷰가 있고 소스를 동적으로 변경하려면 image.startAnimation (animationFadeOut); 앞에 해당 행을 추가 할 수 있습니다. 선. 어떤 문제가 있으면 알려주세요 –

+0

@LovelyGuy, 시도해 봤어? –

관련 문제