如何在一个imageview中为每次点击调用不同的可绘制动画?

问题描述 投票:0回答:1

我有10个图像文件。我想按照1-2,2-3,3-4 ...... 1-2,2-3点击imageview时按顺序播放我的照片...但是当我点击imageview时,只有第一个xml文件正在运行。请帮帮我

    imageView=(ImageView)findViewById(R.id.imageView);
    imageView.setBackgroundResource(R.drawable.animationtesbih);
    imageView.setClickable(true);

    animation=(AnimationDrawable) imageView.getBackground();

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

             animation=(AnimationDrawable) imageView.getBackground();
             animation.start();

             imageView.setBackgroundResource(R.drawable.a1);
             imageView.setBackgroundResource(R.drawable.a2);

        }
    });

这里是我的xml名称a1

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:oneshot="true">
    <item android:drawable="@drawable/t2" android:duration="70"/>
    <item android:drawable="@drawable/t3" android:duration="70"/>

   </animation-list>

这里是其他xml文件名animationtesbih

   <?xml version="1.0" encoding="utf-8"?>
   <animation-list 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true">
   <item android:drawable="@drawable/t1" android:duration="70"/>
   <item android:drawable="@drawable/t2" android:duration="70"/>
</animation-list>

其他xml名称a2

    <animation-list 
     xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true">
    <item android:drawable="@drawable/t3" android:duration="70"/>
    <item android:drawable="@drawable/t4" android:duration="70"/>

   </animation-list>
android animation imageview animationdrawable
1个回答
0
投票

试试这个:

animation=(AnimationDrawable) imageView.getBackground();

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

         animation=(AnimationDrawable) imageView.getBackground();

         animation.start();

         imageView.setBackgroundResource(R.drawable.a1);

    }
});
© www.soinside.com 2019 - 2024. All rights reserved.