1

我有两个相互重叠的图像,我正在将上面的图像动画(滑动)到屏幕右侧,直到它的某些部分保留在屏幕上,这样我就可以将它动画回原来的位置,现在我想得到点击下面的图片开始我的新活动,但我只点击上面的图片,我知道为上面的图片设置动画不会移动它的布局。但我试图移动上图的布局,但移动布局后,上图消失了。

有什么帮助吗?

4

1 回答 1

0

翻译上图后,将其可点击性设置为false,如 aboveImage.setClickable(false); 试试下面的代码,它会工作

动画活动.java:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class AnimationActivity extends Activity {
     ImageView aboveImage;
     ImageView belowImage;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         aboveImage=(ImageView) findViewById(R.id.image_above);
         belowImage=(ImageView) findViewById(R.id.image_below);
        aboveImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                /*belowImage.setVisibility(View.VISIBLE);
                overridePendingTransition(R.anim.move_to_right,R.anim.move_to_left);*/
                Animation animation = new TranslateAnimation(0, 100,0, 0);
                animation.setDuration(1000);
                animation.setFillAfter(true);
                aboveImage.startAnimation(animation);
                aboveImage.setVisibility(0);
                aboveImage.setClickable(false);



            }
        });
        belowImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                startActivity(new Intent(getApplicationContext(),Activity2.class));

            }
        });
    }
}

主.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/image_below"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/cherry" />

    <ImageView
        android:id="@+id/image_above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/amalapaul" />

</RelativeLayout>
于 2012-10-10T06:32:11.740 回答