2013-03-04 64 views
0

停止我刚通过帧动画图像视图应用于帧之后,我只是由帧隐藏ImageView的由帧动画帧在机器人

main.java

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ImageView iv = (ImageView) findViewById(R.id.imageView1); 

    iv.setBackgroundResource(R.anim.animation); 
    AnimationDrawable ac= (AnimationDrawable) iv.getBackground(); 
    ac.start(); 

    //ac.stop(); 
if(ac.isRunning()==false){ 
     iv.setVisibility(View.INVISIBLE); 
    } 
     } 

使用在帧2倍中的图像animation.xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/image1" android:duration="1000"/> 
<item android:drawable="@drawable/image2" android:duration="1000"/> 
</animation-list> 

activity_main.xml中(布局)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#000000" 

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" /> 

    </RelativeLayout> 

林还困惑在哪里停止该动画 ,我需要隐藏的动画图像2后的图像视图,然后重新启动动画以后

我工作的广告图像。所以我需要短时间显示图像,然后再重新启动。

如果有人知道这个解决方案。请帮帮我。

回答

0

ImageView iv =(ImageView)findViewById(R.id.imageView1);

iv.setBackgroundResource(R.anim.animation); 
AnimationDrawable ac= (AnimationDrawable) iv.getBackground(); 
ac.start(); 

您可以简单地把一个空的图片作为动画的最后一个项目:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true" 
> 
<item android:drawable="@drawable/image1" android:duration="1000"/> 
<item android:drawable="@drawable/image2" android:duration="1000"/> 
    <item android:drawable="@drawable/dummy" android:duration="1000"/> 

    </animation-list> 

和单稳= TRUE。

要重新启动,您可以调用onClick方法并调用像下面这样的重新启动: Button btn1 =(Button)findViewById(R.id.btn1);

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

      ImageView iv = (ImageView) findViewById(R.id.imageView1); 

       iv.setBackgroundResource(R.anim.animation); 
       AnimationDrawable ac= (AnimationDrawable) iv.getBackground(); 
       ac.start(); 

     } 
+0

不错的主意,如何重新启动一些动画? – AnanThDev 2013-03-04 12:48:50

+0

@AnanThDev如果它是正确的,然后标记我的答案:)。无论如何,我添加了一些代码reto开始动画。 – Gyonder 2013-03-04 13:14:53

+0

@Gynonder:我不使用Button ..因为我使用imageView作为不同的框架实现广告。所有其他想法? – AnanThDev 2013-03-04 13:54:26