8

Tôi muốn hiển thị hai hoạt ảnh đồng thời theo chương trình không có trong tệp XML. Cần ROTATE và TRANSLATE làm cách nào tôi có thể làm điều đó?Android: Dịch và Hoạt ảnh xoay đồng thời

Vui lòng đề xuất cho tôi một số cách ??????

Đây là mã ma:>

ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1); 
     snowImg1.setVisibility(0); 
     ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2); 
     snowImg2.setVisibility(0); 
     ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3); 
     snowImg3.setVisibility(0); 
     ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4); 
     snowImg4.setVisibility(0); 
     ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6); 
     snowImg6.setVisibility(0); 
     ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5); 
     snowImg5.setVisibility(0); 

     View snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6}; 

     Animation snowMov7 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f); 
     snowMov7.setRepeatCount(Animation.INFINITE); 
     Animation snowMov1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     snowMov1.setDuration(10000); 
     Animation snowMov2 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.4f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     snowMov2.setDuration(10100); 
     Animation snowMov3 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     snowMov3.setDuration(10200); 
     Animation snowMov4 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT,-0.1f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     snowMov4.setDuration(10300); 
     Animation snowMov5 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.6f, Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     snowMov5.setDuration(10400); 
     Animation snowMov6 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.05f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     snowMov6.setDuration(10500); 

     Animation movArray[] = {snowMov1,snowMov2, snowMov3, snowMov4, snowMov5, snowMov6,snowMov7}; 

     for(int i=0;i<6;i++) 
     { 
      movArray[i].reset(); 
      movArray[i].setFillAfter(true); 
      movArray[i].setAnimationListener(this); 
      snowArray[i].startAnimation(movArray[i]);  
      snowArray[i].startAnimation(movArray[6]); 
     } 

Chúng ta có thể sử dụng startAnimation hai lần trong chương trình ??? Xin hãy giúp tôi?

Trả lời

17

Tôi đã thực hiện nó Sử dụng ANIMATIONSET chúng tôi có thể thực hiện việc này.

AnimationSet snowMov1 = new AnimationSet(true); 
     RotateAnimation rotate1 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f); 
     rotate1.setStartOffset(50); 
     rotate1.setDuration(9500); 
     snowMov1.addAnimation(rotate1); 
     TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); 
     trans1.setDuration(12000); 
     snowMov1.addAnimation(trans1); 

Bằng cách này, chúng tôi có thể đặt cho nhiều hoạt ảnh.

Các vấn đề liên quan