SleepNot
SleepNot

Reputation: 3038

Animate RelativeLayout when changing background

Is there a way of animating the changing of background image for a Relative Layout? Thanks.

Upvotes: 0

Views: 798

Answers (1)

Arfan Mirza
Arfan Mirza

Reputation: 686

I found work-around for it,, :)

<ImageView
        android:id="@+id/giftAppBgImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/giftApp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/giftApp"
        android:layout_below="@+id/TopborderBGImage"
        android:clickable="true"
        android:scaleType="fitXY"
        android:src="@drawable/cell_bg" />

    <RelativeLayout
        android:id="@+id/giftApp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/TopborderBGImage"
        android:background="@null"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:src="@drawable/gift_icon" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/imageView1"
            android:text="Gift this app"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/titleMiddleColor"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/moreShaderCell1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:text="Continuous reward for you, InshaAllah!"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/titleMiddleColor" />
    </RelativeLayout>

setOnClickListener

findViewById(R.id.giftAppBgImage).setOnClickListener(this);

@Override
    public void onClick(final View v) {
        // TODO AK-generated method stub
        showLog("catch onClick event!" + v.getClass().getName());
        if (v instanceof ImageView) {
            ((ImageView) v).setImageResource(R.drawable.cell_bg_hover);
            Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.more_animation);
            anim.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation arg0) {
                    // TODO AK-generated method stub

                }

                @Override
                public void onAnimationRepeat(Animation arg0) {
                    // TODO AK-generated method stub

                }

                @Override
                public void onAnimationEnd(Animation arg0) {
                    // TODO AK-generated method stub
                    ((ImageView) v).setImageResource(R.drawable.cell_bg);
                }
            });
            v.startAnimation(anim);

        }
    }

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator">
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:fillAfter="true"
        android:duration="500"/>

</set>

Upvotes: 1

Related Questions