2013-08-21 4 views
2

Je fais une application Android qui a le contrôle de l'animation de zoom d'image avec le début & boutons d'arrêt. (Ie) J'ai deux boutons avec une image.lorsque je clique sur Démarrer, l'image devrait faire une animation zoom. quand je clique sur stop, ça devrait arrêter l'animation., et encore une fois si je clique sur start, il faudrait reprendre le zoom depuis la position arrêtée. Comment pourrais-je faire ça? Voici mon exemple de code de travail:Android Image animation de zoom

ImageView imageView; ScaleAnimation zoom; Animation animée; flotteur gg;

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    zoom = new ScaleAnimation(0, 1, 0, 1); 
    zoom.setDuration(3000); 

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

    ((Button) findViewById(R.id.start)).setOnClickListener(this); 
    ((Button) findViewById(R.id.stop)).setOnClickListener(this); 

} 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
    case R.id.start: 
     zoom.setDuration((long) gg); 
     zoom.start(); 

     break; 
    case R.id.stop: 
     gg = zoom.getDuration(); 
     break; 

    } 

} 

} Merci.

Répondre

4

essayer cette

ZOOM ACTIVITÉ

public class ZoomInActivity extends Activity implements AnimationListener { 

    ImageView imgPoster; 
    Button btnStart; 

    // Animation 
    Animation animZoomIn; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_zoom_in); 

     imgPoster = (ImageView) findViewById(R.id.imgLogo); 
     btnStart = (Button) findViewById(R.id.btnStart); 

     // load the animation 
     animZoomIn = AnimationUtils.loadAnimation(getApplicationContext(), 
       R.anim.zoom_in); 

     // set animation listener 
     animZoomIn.setAnimationListener(this); 

     // button click event 
     btnStart.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // start the animation 
       imgPoster.startAnimation(animZoomIn); 
      } 
     }); 

    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 
     // Take any action after completing the animation 

     // check for zoom in animation 
     if (animation == animZoomIn) {   
     } 

    } 

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

    } 

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

    } 

} 


activity_zoom_in_XML: 


<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:gravity="center"> 

    <ImageView android:id="@+id/imgLogo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/man_of_steel" 
     android:layout_centerInParent="true"/> 

    <Button android:id="@+id/btnStart" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Start Animation" 
     android:layout_marginTop="30dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="20dp"/> 

</RelativeLayout> 

make dossier anim dans res et créer zoom_in.xml

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

    <scale 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="1000" 
     android:fromXScale="1" 
     android:fromYScale="1" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="3" 
     android:toYScale="3" > 
    </scale> 

</set> 
+1

Merci pour votre answer.Im ok.But je dois arrêter et reprendre le zoom à l'arrêt position.Comment puis-je faire – sanjay

+0

comment pouvons-nous zoomer à partir de la même image? –

+0

Merci pour votre réponse.Mais après le zoom comment faire l'imageview – rams

1

facile et simple

  • Créer un dossier res/anim
  • Put descriptions d'animation dans le dossier res/anim
  • Set animation à l'image en utilisant le code ci-dessous

    ImageView image=(ImageView)findViewById(R.id.imageId); 
    image.setAnimation(AnimationUtils.loadAnimation(this,R.anim.zoom_in_anim));