6

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

How can I animate background drawable in android ?

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

Thanks a lot for help Regards, Bruno

EDIT: 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/

Bruno Laurinec
  • 910
  • 2
  • 11
  • 27

1 Answers1

5

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>

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>
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
  • Thanx a lot for reply...could you perhaps shortly describe how to set animation for that image please ? Guess setting it to animated gif won't help, or ? :) – Bruno Laurinec Sep 19 '12 at 22:57
  • @brunolau I'm not sure what you want.Do you want to have a `Drawable Animation`(frame animation) or you want to perform `tweened animation`?A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object – hasanghaforian Sep 19 '12 at 23:17
  • Hi, I'd like to use frame animation...if that means Drawable, then it's the one – Bruno Laurinec Sep 20 '12 at 15:56