在android中创建带有图像的动画序列(SlideShow)

时间:2012-04-08 09:46:37

标签: android android-animation android-imageview android-image

我正在尝试设置不同图像的自定义动画幻灯片。我管理员使用自定义视图为单个图像设置动画。现在我想为我的arraylist中的所有图像设置幻灯片放映。因此,图像将在彼此之后显示oina。现在我有一个自定义视图我需要为每个图像制作更多视图吗?有什么想法吗?

自定义视图:

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

}

}

1 个答案:

答案 0 :(得分:0)

查看ImageSwitcher小部件。它似乎完全符合你的需要。缺少相关文档,因此您可能需要检查其父级ViewSwitcher和ViewAnimator的文档。

基本上,ImageSwitcher执行以下操作:当您向其提供图片时,切换器会播放带有已隐藏图片的动画,并同时播放带有显示图片的动画。在内部,它在两个ImageView之间循环。

您可能遇到的一个问题是ImageSwitcher不会创建其内部图像视图。您可以添加ViewFactory,如ApiDemos所示,或者只是在布局文件中添加这些图片视图:

<ImageSwitcher ...>
    <ImageView ... />
    <ImageView ... />
</ImageSwitcher>