2011-03-02 109 views
2

我一直试图让它使用这个线程工作,但似乎无法得到它的工作。框架动画帮助Android

Frame-by-frame animations

我试图让两个布局之间的屏幕交替,我已经试过很多从状态列表可绘制不同的东西,塑造可绘,甚至flipViews(flipViews没有工作,因为你不能改变背景,只是前景)。

现在我得到一个空指针。如果您想指出我无法在动画中使用布局,那么请这样做,因为这可能是问题,但我无法确定。 任何解决方案,以达到我的最终目标,表示赞赏。

我的onCreate包含以下(减去标准的东西)

ImageView mainimage = (ImageView) findViewById(R.id.main); 
    mainimage.setBackgroundResource(R.anim.blink); 
    AnimationDrawable blinkAnimation = (AnimationDrawable) mainimage.getBackground(); 
    blinkAnimation.start(); 

我的动画文件包含此:(减去UTF东西)

<

animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
     android:oneshot="false"> 
     <item android:drawable="@drawable/royalblue" android:duration="200" /> 
     <item android:drawable="@drawable/blank" android:duration="200" /> 
    </animation-list> 

图像视图中的主要是绝对的牛逼这个空白的xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

</LinearLayout> 

这是我放置在绘制文件夹中的布局,因为我想它是在动画帧。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/blinkBlue" 
    android:background="@color/royalBlue" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    > 

</LinearLayout> 

这是其他布局我已放置在抽拉文件夹,因为我希望它是在动画的帧。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/blinkBlack" 
     android:background="@color/black" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 

     > 

    </LinearLayout> 
+0

具有u解决了这个问题还是仍在寻找答案? – 2011-11-19 09:43:58

+1

使用AnimationDrawable时,您可以轻松地耗尽内存。我想出了一个用drawables来显示动画的类:http://stackoverflow.com/a/12519216/525319 – Yar 2012-09-20 19:11:58

回答

5

我知道,这是相当晚回应,但对于谁在这里面临着同样的问题,别人是我的解决方案:

AnimationDrawable drawable = (AnimationDrawable)getResources().getDrawable(R.anim.amin_list); 
ImageView im = (ImageView) findViewById(R.id.image); 
im .setBackgroundDrawable(drawable); 
im .post(drawable); 

其中amin_list是:

<animation-list android:oneshot="false" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/progress_1" android:duration="150" /> 
    <item android:drawable="@drawable/progress_2" android:duration="150" /> 
    <item android:drawable="@drawable/progress_3" android:duration="150" /> 
    <item android:drawable="@drawable/progress_4" android:duration="150" /> 
</animation-list>