私のMainActivityはバックグラウンドミュージック(サービス経由)で始まり、バックグラウンドミュージックと共にアクティビティが開始されるとすぐに開始するアニメーションを実装しました。開始遅延が実装されていない場合でも、アクティビティの起動から10秒後(音楽はアクティビティの起動から開始)にアニメーションが開始されます。誰か助けてくれますか?私はアンドロイドに新しいです。開始遅延なしでアクティビティを開始するとすぐにアニメーションを開始するには
私は、アニメーションのための次のチュートリアルに従っている: https://www.javacodegeeks.com/2012/10/android-leaf-fall-like-animation-using.html
マイMainActivity.java:
private int[] PICTURES = {
R.mipmap.f1, R.mipmap.f2, R.mipmap.f3, R.mipmap.f4,
};
private Rect display_Size = new Rect();
private RelativeLayout root_Layout;
private ArrayList<View> all_imageViews = new ArrayList<View>();
private float scale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this,MusicService.class);
startService(i);
Display display = getWindowManager().getDefaultDisplay();
display.getRectSize(display_Size);
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
scale = metrics.density;
root_Layout = (RelativeLayout) findViewById(R.id.main_layout);
new Timer().schedule(new ExecTime(),0 , 1000);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int viewId = new Random().nextInt(PICTURES.length);
Drawable d = getResources().getDrawable(PICTURES[viewId]);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
ImageView imageView = (ImageView) inflater.inflate(R.layout.animated_image_view, null);
imageView.setImageDrawable(d);
root_Layout.addView(imageView);
all_imageViews.add(imageView);
RelativeLayout.LayoutParams animationLayout = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
animationLayout.setMargins(0, (int)(-3000*scale), 0, 0);
animationLayout.width = (int) (50*scale);
animationLayout.height = (int) (50*scale);
startAnimation(imageView);
}
};
public void startAnimation(final ImageView animView) {
animView.setPivotX(animView.getWidth()/2);
animView.setPivotY(animView.getHeight()/2);
final ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.setDuration(15000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
int angle = 50 + (int)(Math.random() * 101);
int move = new Random().nextInt(display_Size.right);
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (Float) (animation.getAnimatedValue());
animView.setRotation(angle*value);
animView.setTranslationX((move-100)*value);
animView.setTranslationY((display_Size.bottom + (3000*scale))*value);
}
});
animator.start();
}
private class ExecTime extends TimerTask {
@Override
public void run() {
handler.sendEmptyMessage(Constants.EMPTY_MESSAGE);
}
}
あなたはアニメーションが始まるまであなたのアプリのロゴを表示することができます.. youtubeで見たように..その後、それは空白のページを表示しません – Nitesh
ええ私はそれを行うことができます..しかし、 :) – sonam
ちょうどonCreate()メソッド内のスレッドを処理して何が起こるか教えてください – TapanHP