2013-08-14 13 views
11

एंड्रॉइड में लगातार ImageView ज़ूम-इन और ज़ूम-आउट करने का कोई तरीका है। मैंने नीचे दिए गए कोड का उपयोग करने की कोशिश की, लेकिन ज़ूम फ़ंक्शन में से केवल एक काम कर रहा है।एंड्रॉइड छवि दृश्य ज़ूम-इन और ज़ूम-आउट निरंतर

zoomin.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="20000" 
     android:fromXScale="1" 
     android:fromYScale="1" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="3" 
     android:toYScale="3" > 
    </scale> 

</set> 

zoomout.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="20000" 
     android:fromXScale="1.0" 
     android:fromYScale="1.0" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="0.5" 
     android:toYScale="0.5" > 
    </scale> 

</set> 

और Activity वर्ग है कि मैं कर दिया है:

Animation zoomin, zoomout; //declared as public 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    // animation 
    zoomin = AnimationUtils.loadAnimation(this, R.anim.zoomin); 
    zoomout = AnimationUtils.loadAnimation(this, R.anim.zoomout); 
    bgImage.setAnimation(zoomin); 
    bgImage.setAnimation(zoomout); 
    Thread t = new Thread(new Zoom()); 
    t.start(); 
} 
private class Zoom implements Runnable { 
    @Override 
    public void run() { 
     while (true) {    
      bgImage.startAnimation(zoomin); 
      try { 
       Thread.sleep(8000); 
      } catch (InterruptedException e) { 
            e.printStackTrace(); 
      }    
      bgImage.startAnimation(zoomout); 
     } 
    } 
} 

यहाँ zoomin एनीमेशन काम करने ठीक लग रहा है। क्या zoomin और zoomout एनीमेशन को लगातार कार्यान्वित करने का कोई तरीका है ???

धन्यवाद

उत्तर

15

उपयोग धागा

zoomin.setAnimationListener(new AnimationListener() { 

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

     } 

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

     } 

     @Override 
     public void onAnimationEnd(Animation arg0) { 
      bgImage.startAnimation(zoomout); 

     } 
    }); 

और

zoomout.setAnimationListener(new AnimationListener() { 

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

     } 

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

     } 

     @Override 
     public void onAnimationEnd(Animation arg0) { 
      bgImage.startAnimation(zoomin); 

     } 
    }); 
+1

भयानक! बहुत बहुत धन्यवाद :)) (वाई) – sree127

+3

मैं एंड्रॉइड जोड़ने का सुझाव देता हूं: repeatCount = "1" और एंड्रॉइड: ज़ूमिन और ज़ूमआउट में पैरामीटर स्केल करने के लिए दोहराना मोड = "रिवर्स" और यह बहुत सुंदर काम करता है :) – Arash

0

आप नीचे दिए गए की तरह कुछ का उपयोग कर सकते हैं और संकेत के रूप में

उल्लेख Zommin.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="5000" 
     android:fromXScale="1" 
     android:fromYScale="1" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="1.5" 
     android:toYScale="1.5" 
     > 
    </scale> 

</set> 

Zoomout.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="5000" 
     android:fromXScale="1.5" 
     android:fromYScale="1.5" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="1" 
     android:toYScale="1" > 
    </scale> 

</set> 

और कोड:

zoomin.setAnimationListener(new Animation.AnimationListener() { 

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

      } 

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

      } 

      @Override 
      public void onAnimationEnd(Animation arg0) { 
       imageView.startAnimation(zoomout); 

      } 
     }); 
संबंधित मुद्दे