Android 活动 - 背景可绘制动画 [英] Android activity - background drawable animated

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

问题描述

问题很简单,但是对于像我这样的android初学者还没有找到任何简单的答案......

question simple, however haven't found any simple answer for android beginner such as I am...

如何在 android 中为可绘制的背景设置动画?

How can I animate background drawable in android ?

如果可能的话,我想通过一些简单易懂的方式来实现bakcground动画.

I'd like to achieve the bakcground animation if possible by some simple and easy-tounderstand way.

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

Thanks a lot for help Regards, Bruno

经过一番谷歌搜索后,我设法实现了我的目标.我使用了 hasanghaforian 描述的方法和在这个简单的动画示例 http 中找到的应用机制://code.google.com/p/android-animation-example/

After some googling I've managed to accomplish my goal. I've used approach described by hasanghaforian and applied mechanics found in this straight-forward animation example http://code.google.com/p/android-animation-example/

推荐答案

你可以使用RelativeLayout或者AbsoluteLayout,在里面放一个图片(覆盖它的父级),然后挂载当前activity的布局.现在如果你为那个设置动画图片,您的活动背景似乎是动画.
例如,假设这是您的活动的当前布局:

You can use RelativeLayout or AbsoluteLayout ,put an image (that covers it's parent) in it and then mount current layout of activity.Now if you set animation for that image,it seems that background of your activity animates.
For example suppose this is current layout of your activity:

<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 of main layout):

Now this layout looks like previous layout and you can set animation for image that it's ID is img1(it seems as backgr:ound of main layout):

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

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

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