我使用sdk创建了一个“添加”按钮,所以当我按下那个“添加”按钮时我希望它向左移动,当我再次按下时回到原来的位置。我遇到的问题是按钮在按下时只能向左移动,并且在我尝试再次按下后无法回到原来的位置。我的 if...else 函数有问题吗?任何帮助将不胜感激。
public class TestImage2 extends Activity {
/** Called when the activity is first created. */
ImageView image_plus;
ImageView image_subtract;
ImageView image_multiply;
ImageView image_div;
String op;
boolean pergi = false;
final Animation animation = new TranslateAnimation(0,100,0,0);
final Animation animation2 = new TranslateAnimation(100,0,0,0);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image_plus = (ImageView)findViewById(R.id.test_image);
image_subtract = (ImageView)findViewById(R.id.test_image2);
image_multiply = (ImageView)findViewById(R.id.test_image3);
image_div = (ImageView)findViewById(R.id.test_image4);
image_plus.setOnClickListener(new OnClickListener(){
public void onClick(View view) {
if(pergi == false)
{
animation.setDuration(1000);
image_plus.startAnimation(animation);
pergi= true;
animation.setFillAfter(true);
}
else
{
animation2.setDuration(1000);
image_plus.startAnimation(animation2);
pergi = false;
animation2.setFillAfter(true);
}
}});