更改背景时动画RelativeLayout

时间:2012-08-06 03:47:50

标签: android animation layout

是否有一种方法可以为相对布局设置背景图像的更改动画?感谢。

1 个答案:

答案 0 :(得分:1)

我找到了它的解决方法,:)

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