0

I'm having trouble finding the answer to this question.

I want to emulate the transformation of an image inside an ImageView e.g.

image1 = (ImageView) findViewById(R.id.image1);
animationSlideInLeft = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
image1.startAnimation(animationSlideInLeft);

But that's not what I want exactly. Instead, I want to transform a drawable set as a linear layout background.

linearLayout.setBackground(drawable); 

How can I transform the drawable and make it move from left to right inside of the LinearLayout?

the_prole
  • 8,275
  • 16
  • 78
  • 163

2 Answers2

1

I'm not sure if this will work for what you're after but have you thought about setting an ImageView inside of the LinearLayout and making the height and width the same as the LinearLayout instead of setting the LinearLayout background? You can that animate the ImageView like you are doing now and it will give the same result.

vguzzi
  • 2,420
  • 2
  • 15
  • 19
  • I had thought of that, but then how can I overlay the widgets inside the linear layout over the image view? – the_prole Oct 16 '15 at 07:54
  • 1
    You would have to wrap the `LinearLayout` inside a `RelativeLayout`. Place the `ImageView` in the `RelativeLayout` and the rest of your view inside the `LinearLayout` – vguzzi Oct 16 '15 at 07:55
  • Thanks, you are correct, but Sese answered before you with the suggestion to use relative layout. I have upvoted your comments and answers none the less. Thank you. – the_prole Oct 16 '15 at 08:04
  • Actually, I answered before him - check the answered x mins ago. But no worries! Thanks for the up-vote! – vguzzi Oct 16 '15 at 08:05
  • 1
    Ah I didn't say about the RelativeLayout until the comments though - got it! – vguzzi Oct 16 '15 at 08:06
1

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>

Found here: Android activity - background drawable animated

Community
  • 1
  • 1
Sebastian Schneider
  • 4,896
  • 3
  • 20
  • 47