2013-02-04 28 views
15

Bu animasyon hakkında hiçbir fikrim yok.ImageView için nasıl animasyon yapabilirim?

Bunu nasıl xml yoluyla yapabilirim? Ya da başka bir çözüm? senin Helf için

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
    android:fillAfter="true"> 
    ...... 
</set> 

Teşekkür

Sen nasıl titreşim animasyon işleri için bağlantısını aşağıda ödeme yapabilirsiniz
+0

çeki bu cevabı: Bu benim için çok çalıştı http://stackoverflow.com/a/9449590/607968 – rDroid

cevap

11

?

1) Shaking animation in android
2) Vibration animation

Seni yardımcı olacağını umuyoruz.

sayesinde

+0

Merhaba, Titreşim demek istemiyorum Android Cihaz. ImageView –

+1

'un animasyonunu kastediyorum. Görüntü görünümünü sarsmak istediğinizi mi söylemek istiyorsunuz? – GrIsHu

+0

Evet, demek istediğim bu, –

8

Bu kod, yatay yönde bir görüntü sallar

shake.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="1000" 
    android:fromXDelta="0" 
    android:interpolator="@anim/cycle_5" 
    android:toXDelta="10" /> 

cycle_5.xml

<?xml version="1.0" encoding="utf-8"?> 
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" 
    android:cycles="5" /> 

yöntem özelliği animasyon) çalışma için beni aşağıdaki kodu kullanarak ImageView

public void onShakeImage() {  
    Animation shake; 
    shake = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shake); 

    ImageView image; 
    image = (ImageView) findViewById(R.id.image_view); 

    image.startAnimation(shake); // starts animation 
} 
+0

setAnimation başlatılamıyor. Animasyonu gerçekten başlatmak için startAnimation (sarsıntı) kullanmanız gerekir. – Eli

2

1) titreşim veya 2) çalkalama (sallamak.

ObjectAnimator rotate = ObjectAnimator.ofFloat(animateView, "rotation", 0f, 20f, 0f, -20f, 0f); // rotate o degree then 20 degree and so on for one loop of rotation. 
// animateView (View object) 
     rotate.setRepeatCount(20); // repeat the loop 20 times 
     rotate.setDuration(100); // animation play time 100 ms 
     rotate.start(); 
0

anim dizininde animasyon dosyası oluşturun:

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="200" 
    android:fromDegrees="-10" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="infinite" 
    android:repeatMode="reverse" 
    android:toDegrees="10" /> 



Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake); 
your_view.startAnimation(shake);