背景动画图像

时间:2013-09-21 06:31:40

标签: android android-animation

我想知道如何做到以下几点。我希望我的应用程序背景能够被动画化(让我们说鸟类的飞行类似于活壁纸的样子)。这通常是使用GIF背景完成还是我需要编码动画或使用绘画/绘图功能来绘制动画(我希望不会!)

任何指针都会受到赞赏,因为我不知道该怎么做

谢谢

1 个答案:

答案 0 :(得分:8)

您也可以使用GIF图像,但首先将该GIF转换为帧

in xml

<ImageView 
    android:layout_width="match_parent"
android:layout_height="match_parent" 
android:id="@+id/img1"
/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/img1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="156dp"
    android:text="submit"
     />

在java中

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView i = (ImageView)findViewById(R.id.img1);
    i.setBackgroundResource(R.drawable.gif);

    AnimationDrawable pro = (AnimationDrawable)i.getBackground();
    pro.start();
}   
}

在drawable创建动画文件中

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/selected" android:oneshot="false">  
  <item android:drawable="@drawable/frame0" android:duration="50" />
  <item android:drawable="@drawable/frame1" android:duration="50" /> 
  <item android:drawable="@drawable/frame2" android:duration="50" />
  <item android:drawable="@drawable/frame3" android:duration="50" />
  <item android:drawable="@drawable/frame4" android:duration="50" />
  <item android:drawable="@drawable/frame5" android:duration="50" />
  <item android:drawable="@drawable/frame6" android:duration="50" />
  <item android:drawable="@drawable/frame7" android:duration="50" />
  <item android:drawable="@drawable/frame8" android:duration="50" />
  <item android:drawable="@drawable/frame8" android:duration="50" />
  <item android:drawable="@drawable/frame9" android:duration="50" />
  <item android:drawable="@drawable/frame10" android:duration="50" />

</animation-list>

希望这可以帮到你