2012-09-17 40 views
6

问题简单,但还没有找到Android的初学者如我任何答案很简单...Android的活动 - 背景绘制动画

我怎样才能在Android的动画背景绘制?

我想通过一些简单易懂的方式实现bakcground动画。

非常感谢帮助 问候,布鲁诺

编辑:一些谷歌搜索后,我已经成功实现我的目标。我已经使用hasanghaforian描述的方法和应用这种直截了当的动画例如http://code.google.com/p/android-animation-example/

回答

5

可以使用的RelativeLayout或AbsoluteLayout发现机制,把图像(覆盖它的父)中,然后安装活动的当前布局。现在,如果您为该图片设置了动画,那么您的动画背景看起来就像动画。
例如,假设这是你的活动当前布局:

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

    <ImageView 
     android:id="@+id/img" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 
</LinearLayout> 

现在这个布局看起来像以前的布局,可以为图像,它的ID是img1设置动画(它似乎backgr:主要布局的ound) :

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



    <ImageView 
     android:id="@+id/img1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_x="0dp" 
     android:layout_y="0dp" 
     android:src="@drawable/bright_sun" /> 
    <LinearLayout 
    android:id="@+id/vg2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

     <ImageView 
     android:id="@+id/img" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

</RelativeLayout> 
+0

非常感谢您的回复......请问您能否简要描述如何为该图片设置动画? 猜猜将它设置为GIF动画不会有帮助吗? :) –

+0

@brunolau我不确定你想要什么。你想有一个'Drawable Animation'(frame animation)或者你想执行'tweedned animation'吗?一个补间动画可以执行一系列简单的转换(position ,大小,旋转和透明度)在一个视图对象的内容 – hasanghaforian

+0

嗨,我想使用帧动画...如果这意味着可绘制,那么它是一个 –