如何启动android eclipse
我正在制作一个游戏,游戏的目标是防止图像掉落,我想要的是,当图像到达屏幕底部时,它将发出启动新活动的意图。请帮助我。我设法使图像下降,我想知道的是当图像到达屏幕底部时如何触发意图如何启动android eclipse,android,eclipse,animation,imageview,Android,Eclipse,Animation,Imageview,我正在制作一个游戏,游戏的目标是防止图像掉落,我想要的是,当图像到达屏幕底部时,它将发出启动新活动的意图。请帮助我。我设法使图像下降,我想知道的是当图像到达屏幕底部时如何触发意图 package com.example.crashthetrash; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import andro
package com.example.crashthetrash;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class Game extends Activity {
int posy;
int posy2;
int posy3;
int posy4;
int posy5;
int posy6;
int dur;
int dur2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
dur = 5000;
dur2 = dur - 10;
final ImageView chips = (ImageView) findViewById(R.id.chips);
final TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 500.0f);
animation.setDuration(dur);
animation.setRepeatCount(0);
animation.setRepeatMode(0);
animation.setFillAfter(true);
chips.startAnimation(animation);
chips.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
posy = chips.getTop();
posy2 = 0 - posy;
dur2 = dur2 - 100;
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, posy2, 500.0f);
animation.setDuration(dur2);
animation.setRepeatCount(0);
animation.setRepeatMode(0);
animation.setFillAfter(true);
chips.startAnimation(animation);
return true;
}
});
final ImageView fish = (ImageView) findViewById(R.id.fish);
final TranslateAnimation animation2 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 500.0f);
animation2.setDuration(dur);
animation2.setRepeatCount(0);
animation2.setRepeatMode(0);
animation2.setFillAfter(true);
fish.startAnimation(animation2);
fish.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
posy3 = fish.getTop();
posy4 = 0 - posy;
dur2 = dur2 - 100;
TranslateAnimation animation2 = new TranslateAnimation(0.0f, 0.0f, posy4, 500.0f);
animation2.setDuration(dur2);
animation2.setRepeatCount(0);
animation2.setRepeatMode(0);
animation2.setFillAfter(true);
fish.startAnimation(animation2);
return true;
}
});
final ImageView paper = (ImageView) findViewById(R.id.paper);
final TranslateAnimation animation3 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 500.0f);
animation3.setDuration(dur);
animation3.setRepeatCount(0);
animation3.setRepeatMode(0);
animation3.setFillAfter(true);
paper.startAnimation(animation3);
paper.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
posy5 = paper.getTop();
posy6 = 0 - posy;
dur2 = dur2 - 100;
TranslateAnimation animation3 = new TranslateAnimation(0.0f, 0.0f, posy6, 500.0f);
animation3.setDuration(dur2);
animation3.setRepeatCount(0);
animation3.setRepeatMode(0);
animation3.setFillAfter(true);
paper.startAnimation(animation3);
return true;
}
});
if(animation.hasEnded() || animation2.hasEnded() || animation3.hasEnded())
{
Intent intent = new Intent(Game.this, Restart.class);
startActivity(intent);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return super.onTouchEvent(event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.game, menu);
return true;
}
}
你指的是哪一个字段?你的意图代码看起来很正确,只要检查一下你的指针是否进入了IF循环,我不明白你的意思。我是eclipse的新手。你能通过我的代码告诉我你的意思吗。非常感谢。一切都正常,只有{if}语句。我也在想我是否可以使用switch来完成这个任务。请帮忙D