どうすればthrow any object(Stone)
continuously
をmoving Horizontally object
にすることができますか? 翻訳アニメーションを連続的に使用して石を投げるスレッドを使用しましたが、メモリ使用量が非常に多く、デバイスが3-4分後にスローダウンします。問題を解決するにはどうすればよいですか?androidアニメーションでスレッドを処理する方法
0
A
答えて
2
あなた自身がSurfaceView
を実装するのが最もよいと思います。その中で、アニメーションオブジェクト(専用スレッドを使用して)をビューアニメーションよりもはるかに魅力的なものにすることができます。 (もちろん、コードの一部を書き直す必要がありますが、長期的には最良のものになるかもしれません)。
SurfaceView
をお試しになる場合は、アンドロイドのLunar Landerの例をご覧ください。
例:
public class ThrowView extends SurfaceView implements SurfaceHolder.Callback, OnGestureListener{
//The OnGestureListener can detect a fling motion.
private class DrawingThread extends Thread{
private final float timefactor = 0.0001f; //This is used to make the animation a bit slower. Play with this value if the animation seems too be to slow or too fast.
private final float damp = 0.9; //This is used to slow down the object. If it stops too fast or slow, this is the value to change.
private float stoneX = 0; //The x-coordinate of our stone object. Use this when drawing.
private float stoneY = 0; //The y-coordinate of our stone object. Use this when drawing.
@Override
public void run(){
while(running){
Canvas c = null;
try{
c = surfaceHolder.lockCanvas(null);
synchronized (surfaceHolder) {
updatePhysics();
doDraw(c); //doDraw is not in this example, but it should essentially just draw our object at stoneX, stoneY.
}
}finally{
if(c!=null) surfaceHolder.unlockCanvasAndPost(c);
}
SystemClock.sleep(40);
}
private void updatePhysics(long time){
//Calculate how much time has passed since last step:
time1 = System.currentTimeMillis();
dT = (time1 - time2)*timefactor;
time2 = time1;
//Move the stone in x depending on the time and velocity:
stoneX += vX*dT;
//Decrease the velocity:
vX -= dT*damp:
}
}
protected volatile float vX = 0; //This is the x-speed. To be able to throw in y too, just make another variable for that.
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//This is our onFling, here we take the velocity of the users fling and set our variable to that.
//Note that this value is based on pixels.
vX = velocityX;
return true;
}
@Override
public boolean onDown(MotionEvent e) {
//The onDown should return true so onFling can be activated:
return true;
}
}
この例では、使用を容易にするために月面着陸サンプルに従って行われます。多くのメソッド(この例では不要)はここでは省略されていますが、Lunar Landerに基づいて実装できます。
関連する問題
- 1. Androidでスレッドを処理する
- 2. Javaスレッドの処理方法
- 3. ASP.NETで未処理のスレッド例外を処理する方法は?
- 4. Android OkHttp ETagを処理する方法
- 5. Android:向きを変えながらレイアウトのアニメーションを処理する方法は?
- 6. Pythonで処理するスレッド
- 7. MVVMビューモデルでC#WPFスレッドを処理する方法
- 8. カーネル内のスレッドを適切に処理する方法は?
- 9. Rubyスレッドで例外を処理する
- 10. Androidデバイスの物理カメラボタンを処理する方法
- 11. android:画像処理のメモリ管理を改善する方法
- 12. AndroidでBluetooth経由でInputStreamとOutputStreamを処理する方法
- 13. SQLテーブルを更新するスレッドでErrorEventhandlerを処理する方法は?
- 14. AndroidでVolleyのレスポンスを処理する方法
- 15. Androidでサービス情報を処理する方法
- 16. Android用AndEngineでスプライトとTextureRegionsを処理する方法
- 17. AndroidでAffineTransformを処理する方法は?
- 18. Androidでクリックされたボタンを処理する方法は?
- 19. Android SDKで分割ビューを処理する方法
- 20. Androidで長いクリックを処理する方法
- 21. Androidゲームでクラス、アクティビティデザインを処理する方法
- 22. Androidで処理ライブラリを使用する方法
- 23. Androidで連絡先の変更を処理する方法は?
- 24. AndroidでSQLテーブルの変更を処理する方法
- 25. AndroidでSOAPメソッド例外を処理する方法
- 26. スレッド処理通知
- 27. Silverlightファイル処理スレッド
- 28. Androidで仕事を処理するためのスレッド処理でのバックグラウンドプロセスの設定
- 29. EJB3を使用して複数のスレッドでデータを処理する方法は?
- 30. スレッドを使用してopenCVとMFCで画像を処理する方法
私はジェスチャーonFling()を使用してオブジェクトをスローすることができます。私はいくつかの例を提供していますか? – Geetanjali
投げに使用するメソッドの例を追加しました。欠落している部分は、月の着陸船での作り方を見ることができますが、コースには若干の適応があります。 :) – Jave
私たちは、 "連続して動いているターゲット上のジェスチャリスナーによってオブジェクトをonFling()にスローしたい"ことができるのですか?それで、両方を単一のSurface Viewで行うことができます......どうすればできますか? ???? – Geetanjali