Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android activity - background drawable animated

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/

like image 286
Bruno Laurinec Avatar asked Sep 17 '12 23:09

Bruno Laurinec


1 Answers

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>
like image 192
hasanghaforian Avatar answered Oct 23 '22 18:10

hasanghaforian