背景动画图像 [英] Background animated image

查看:99
本文介绍了背景动画图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何做到以下几点.我希望我的应用程序背景具有动画效果(比如说,鸟儿在飞翔,就像活着的墙纸一样).通常是使用GIF背景完成此操作,还是需要对动画进行编码或使用绘画功能来绘制动画(我希望不是!)

I am wondering how I can do the following. I want my app background to be animated (let's say birds flying sort of what live wall papers look like). Is this usually done using GIF background or do I need to code animation or use paint/draw functionality to draw animations (I hope not!)

感谢任何指针,因为我不确定该怎么做

Any pointer is appreciated as I am not sure how to do that

谢谢

推荐答案

您也可以通过使用GIF图像来做到这一点,但首先将GIF转换为帧

You can do it by using GIF image also, but first convert that GIF to frames

在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();
}   
}

在可绘制的创建动画文件中

in drawable create animation file

<?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>

希望这可能对您有帮助

这篇关于背景动画图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆