根据我首先单击的动画,第二个动画将始终触发第一个动画。我不知道我做错了什么。
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class Test extends Activity {
ImageView img_left;
ImageView img_right;
Button left;
Button right;
TranslateAnimation moveup;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
moveup = new TranslateAnimation(0, 0, 0, -900);
moveup.setDuration(2000);
moveup.setFillAfter(true);
left = (Button) findViewById(R.id.left);
right = (Button) findViewById(R.id.right);
img_left = (ImageView) findViewById(R.id.image_left);
img_right = (ImageView) findViewById(R.id.image_right);
right.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
img_right.startAnimation(moveup);
Toast.makeText(getApplicationContext(), "right", Toast.LENGTH_LONG).show();
}
});
left.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
img_left.startAnimation(moveup);
Toast.makeText(getApplicationContext(), "left", Toast.LENGTH_LONG).show();
}
});
}
}
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context=".First" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<Button
android:id="@+id/left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000EE"
android:text="" />
<Button
android:id="@+id/right"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000EE"
android:text="" />
</LinearLayout>
<ImageView
android:id="@+id/image_left"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/cue1" />
<ImageView
android:id="@+id/image_right"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/cue2" />
</RelativeLayout>