2013-12-17 3 views
0

Я хочу, чтобы повернуть изображение, другие изображения также перемещаться относительно анимационного изображенияКак вращать анимацию с объектом анимации

XML является:

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="86dp" 
    android:src="@drawable/top_pati" /> 
<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView1" 
    android:layout_below="@+id/imageView1" 
    android:src="@drawable/top_pativertical" /> 
<ImageView 
    android:id="@+id/imageView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/imageView1" 
    android:layout_below="@+id/imageView1" 
    android:src="@drawable/top_pativertical" /> 

Java код так:

imageView= (ImageView) findViewById(R.id.imageView1); 

    imageView.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      RotateAnimation anim = new RotateAnimation(0,45 , Animation.RELATIVE_TO_SELF, 
        0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
      anim.setInterpolator(new LinearInterpolator()); 
      anim.setDuration(500); 
      anim.setFillEnabled(true); 
      anim.setFillAfter(true); 
      imageView.startAnimation(anim); 

     } 


    }); 

Я хочу использовать анимацию объекта, здесь я использую анимацию вращения, которая не перемещает фактическую позицию изображения. как я могу использовать анимацию объекта.

ответ

0

создать этот XML-файл и установить этот файл в ImageView в XML

<?xml version="1.0" encoding="utf-8"?> 
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/loading" 
    android:pivotX="50%" 
    android:pivotY="50%" /> 
+0

Анимация аним = AnimationUtils.loadAnimation (getApplicationContext(), R.anim.animation); \t \t \t \t imageView.startAnimation (anim); исключение на анимированное вращение – user3106818

+0

исключение? – dipali

+0

java.lang.RuntimeException: Неизвестное имя анимации: animated-rotate – user3106818

0
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f); 
anim.setInterpolator(new LinearInterpolator()); 
anim.setRepeatCount(Animation.INFINITE); 
anim.setDuration(700); 

// Start animating the image 
final ImageView splash = (ImageView) findViewById(R.id.splash); 
splash.startAnimation(anim); 

// Later.. stop the animation 
splash.setAnimation(null); 
+0

http://stackoverflow.com/questions/20609145/how-to-rotate-imageview-from-its-centre-position-using-object-animation?noredirect=1#comment30841599_20609145 в этой ссылке см. изображение i хочу, чтобы мое левое изображение было выше (ссылка с другим изображением), а другие спускаются, так что я могу сделать . Мой макет также устанавливает изображение и изображениеview3 ниже imageview1 поэтому, когда он анимируется, то почему изображения и изображенияviewview3 не находятся ниже imageview1 – user3106818

1
final ImageView mytrain = (ImageView) findViewById(R.id.train); 
    final Animation traintween = AnimationUtils.loadAnimation(this,R.anim.treinanimation); 
    final Animation trainfade = AnimationUtils.loadAnimation(this,R.anim.trainfade); 
    AnimationSet s = new AnimationSet(false);//false mean dont share interpolators 
    s.addAnimation(traintween); 
    s.addAnimation(trainfad); 
    mytrain.startAnimation(s); 

этот пример установлен применить несколько анимации на одном изображении ..

Смежные вопросы