2013-02-04 45 views
15

Tôi không có ý tưởng về hoạt ảnh này.Làm cách nào để tạo hoạt ảnh rung cho ImageView

Tôi có thể làm điều đó thông qua xml như thế nào? Hoặc giải pháp khác?

<?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> 

Cám ơn giúp xoa của bạn

+0

kiểm tra câu trả lời này: Điều này làm việc tuyệt vời cho tôi http://stackoverflow.com/a/9449590/607968 – rDroid

Trả lời

11

Bạn có thể kiểm bên dưới liên kết đến cho cách thức hoạt động rung động?

1) Shaking animation in android
2) Vibration animation

Tôi hy vọng nó sẽ giúp bạn.

Cảm ơn

+0

Hi, tôi không có nghĩa là các Rung Thiết bị Android. Tôi có nghĩa là các hình ảnh động của ImageView –

+1

Bạn có nghĩa là để nói rằng bạn muốn lắc imageview? – GrIsHu

+0

Vâng, đây là ý của tôi là –

8

Mã này lắc một cái nhìn theo hướng ngang

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

Phương pháp để lắc 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

setĐịnh dạng không khởi động. Bạn cần sử dụng startAnimation (lắc) để thực sự bắt đầu hoạt ảnh. – Eli

2

1) rung hoặc 2) lắc (sử dụng hình ảnh động tài sản) đoạn mã sau làm việc cho tôi.

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

Tạo tập tin hình ảnh động trong thư mục anim:

<?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); 
Các vấn đề liên quan