2012-04-08 305 views
0

我正在嘗試設置不同圖像的自定義動畫幻燈片。我管理使用自定義視圖爲單個圖像設置動畫。現在我想爲我的數組列表中的所有圖像設置幻燈片放映。因此,圖像將在彼此之後顯示。現在我有一個自定義視圖,我需要爲每個圖像製作更多視圖嗎?有任何想法嗎?使用android中的圖像創建動畫序列(SlideShow)

自定義視圖:

public class AnimationPhotoViewA extends ImageView { @Overridepublic void setImageBitmap(Bitmap bm) {super.setImageBitmap(bm);image= bm;}

活動:

 public class PhotoSyncActivity extends Activity implements AnimationListener { 
@Override 
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); 

    setContentView(R.layout.photo_sync_screen); 
    ArrayList<String> photoPaths = new ArrayList<String>(); 
    photoPaths = getAllPhotos(Environment.getExternalStorageDirectory(), 
      photoPaths); 
    images = new Bitmap[photoPaths.size()]; 
    Log.v(ACCESSIBILITY_SERVICE, "photo array!" + photoPaths); 

    apa1 = (AnimationPhotoViewA) findViewById(R.id.animation_viewA); 

      //START ANIMATION 

    animationmove = PhotoAnimationProcess.moveOne(this,apa1,animationmove); 

    File imgFile = new File(photoPaths.get(0)); 

    if (imgFile.exists()) 
    { 
     images[0] = decodeFile(imgFile); 
    } 
} 

@Override 
protected void onStart() { 
    // TODO Auto-generated method stub 
    super.onStart(); 


    // SET IMAGE IN THE VIEW 
    apa1.setImageBitmap(resizedimage); 

} 
private void addPicture() { 
    // TODO Auto-generated method stub 

} 



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

} 

public void onAnimationEnd(Animation animation) 
{ 
    // TODO Auto-generated method stub 

    switch (animationmove) 
    { 
    case move1: 
     animationmove = PhotoAnimationProcess.moveOne(this, apa1, animationmove); 
     break; 
    case move2: 
     addPicture(); 
     animationmove = PhotoAnimationProcess.moveTwo(this,apa1,animationmove); 

     break; 
    case move3: 
     animationmove = PhotoAnimationProcess.moveThree(this,apa1,animationmove); 
     break; 
    case move4: 
     animationmove = PhotoAnimationProcess.moveFour(this,apa1,animationmove);; 
     break; 
    case move5: 
     animationmove = PhotoAnimationProcess.moveFive(this,apa1,animationmove); 
     break; 

    default: 
     break; 
    } 

    Log.v(ALARM_SERVICE, "Animation Type" + animation.toString()); 

} 



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

} 

}

回答

0

看看在ImageSwitcher部件。它似乎正是你所需要的。缺少相關文檔,因此您可能需要檢查其父母ViewSwitcher和ViewAnimator的文檔。

基本上ImageSwitcher會執行以下操作:當您向其提供圖片時,切換器會播放帶有已隱藏圖片的動畫,並且同時用所提供的圖片播放動畫。它在內部在兩個ImageView之間循環。

您可能會遇到的一個問題是ImageSwitcher不會創建其內部圖像視圖。爲你解答

<ImageSwitcher ...> 
    <ImageView ... /> 
    <ImageView ... /> 
</ImageSwitcher> 
+0

感謝:您既可以添加爲ApiDemos所示的ViewFactory或者只是添加在佈局文件,這些圖像的看法!我需要這些圖像以專門的動畫在語法上運行,而不關注某個圖像。我不認爲ImageSwitcher會幫助我 – user182192 2012-04-08 11:48:08

+0

你誤解了Darth Beleg的答案。 ImageSwitcher(或者其他任何切換器)讓您可以輕鬆訪問動畫,以便很好地交換圖像。你可以用你想要的任何Bitmaps以編程方式填充這些圖像,並節省自己重新發明這個輪子的麻煩(這就是你上面做的)。 – 2012-04-18 15:50:29