SORU
4 Ocak 2012, ÇARŞAMBA


Android İmageView ile fade ve fade out

Ben inşa ediyorum bir slayt gösterisi ile biraz sorun yaşıyorum.

Ve fade out fade xml: 2 animasyonlar oluşturduk

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

    <?xml version="1.0" encoding="UTF-8"?>
       <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>

Yapmak'trying, bir İmageView kullanarak görüntüleri değiştirmek için ne şu anda görüntülenen resim kaybolacak kadar etkisi solmaya, ve bir tane daha yok olacaktır. Bir görüntü zaten, sorun olmadan bu Görüntü yumuşak geçiş yapabilirim, bu seti olduğunu düşünüyor:

    Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
    imageView.startAnimation(fadeoutAnim);

Ama sonra, görüntülenecek sonraki görüntüyü ayarlayın:

    imageView.setImageBitmap(secondImage);

Sadece imageView gösterir, ve bu görüntüyü gizler animasyon hazırladım,... ... bir yolu var mı onu da yaptığımda, yani, düzeltmek için fadeimageView.setİmageBitmap(secondİmage);görüntü hemen kendini gösterir ve animasyon solmaya yürütülür? komut,

CEVAP
6 Mayıs 2012, Pazar


Sizinle aynı hedefe ulaşmak için istedim, eğer geçersen tam olarak aşağıdaki yöntemi bir İmageView ve görüntü drawables başvuru listesini yazdım.

ImageView demoImage = (ImageView) findViewById(R.id.DemoImage);
int imagesToShow[] = { R.drawable.image1, R.drawable.image2,R.drawable.image3 };

animate(demoImage, imagesToShow, 0,false);  



  private void animate(final ImageView imageView, final int images[], final int imageIndex, final boolean forever) {

  //imageView <-- The View which displays the images
  //images[] <-- Holds R references to the images to display
  //imageIndex <-- index of the first image to show in images[] 
  //forever <-- If equals true then after the last image it starts all over again with the first image resulting in an infinite loop. You have been warned.

    int fadeInDuration = 500; // Configure time values here
    int timeBetween = 3000;
    int fadeOutDuration = 1000;

    imageView.setVisibility(View.INVISIBLE);    //Visible or invisible by default - this will apply when the animation ends
    imageView.setImageResource(images[imageIndex]);

    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setInterpolator(new DecelerateInterpolator()); // add this
    fadeIn.setDuration(fadeInDuration);

    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new AccelerateInterpolator()); // and this
    fadeOut.setStartOffset(fadeInDuration   timeBetween);
    fadeOut.setDuration(fadeOutDuration);

    AnimationSet animation = new AnimationSet(false); // change to false
    animation.addAnimation(fadeIn);
    animation.addAnimation(fadeOut);
    animation.setRepeatCount(1);
    imageView.setAnimation(animation);

    animation.setAnimationListener(new AnimationListener() {
        public void onAnimationEnd(Animation animation) {
            if (images.length - 1 > imageIndex) {
                animate(imageView, images, imageIndex   1,forever); //Calls itself until it gets to the end of the array
            }
            else {
                if (forever == true){
                animate(imageView, images, 0,forever);  //Calls itself to start the animation all over again in a loop if forever = true
                }
            }
        }
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
        }
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub
        }
    });
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • backyardjay

    backyardjay

    8 ŞUBAT 2009
  • Gali B

    Gali B

    1 EYLÜL 2006
  • hockeywebcasts

    hockeywebcas

    31 EKİM 2012