2011-12-02 4 views

答えて

8

どのAndroidバージョンをお使いですか? APIレベル11以降は、あなたのカーブ変換を簡単に実装できるカスタムAnimatorsを使用することができます。

例:

View view; 
animator = ValueAnimator.ofFloat(0, 1); // values from 0 to 1 
animator.setDuration(5000); // 5 seconds duration from 0 to 1 
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() 
{ 
    @Override 
    public void onAnimationUpdate(ValueAnimator animation) { 
     float value = ((Float) (animation.getAnimatedValue())) 
        .floatValue(); 
     // Set translation of your view here. Position can be calculated 
     // out of value. This code should move the view in a half circle. 
     view.setTranslationX((float)(200.0 * Math.sin(value*Math.PI))); 
     view.setTranslationY((float)(200.0 * Math.cos(value*Math.PI))); 
    } 
}); 

あなたはその下のバージョンを使用する場合

は、手動でアニメーションリスナー

EDITをアニメーションを翻訳使用して設定する複数の線形変換を連結する私の知る限り唯一の可能性があります私はそれがうまくいきたい&をコピーして、自分のアプリケーションのコードをペースト(短縮)しました。

+0

アンドロイド3.0でカーブ変換を準備するためのサンプルコードを提供してください。 – user884126

+0

あります。私はそれが動作することを願って –

+0

@ js-サー、私は9歳のアンドロイドライブラリを使用して11未満のAPIレベルの湾曲したアニメーションを実装できますか? –

-1

次のWebリンクを検討してください。これはCのゲームです。あなたはprojectile()関数を分離し、その中で定義された変数を理解する必要があります。一度それを取得すると、独自のコードで実装してください。ここで

http://www.daniweb.com/software-development/c/code/216266

+2

これは理論的には疑問に答えるかもしれませんが、答えを編集してソリューションの重要な部分を含めること、および参照用のリンクを提供することが望ましい(http://meta.stackexchange.com/q/8259)。 –

3

私が使用するアニメーターです:

目的:パスに沿って表示 "ビュー" に移動 "パス"

アンドロイドV21の+:

// Animates view changing x, y along path co-ordinates 
ValueAnimator pathAnimator = ObjectAnimator.ofFloat(view, "x", "y", path) 

アンドロイドV11 +:

// Animates a float value from 0 to 1 
ValueAnimator pathAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); 

// This listener onAnimationUpdate will be called during every step in the animation 
// Gets called every millisecond in my observation 
pathAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

float[] point = new float[2]; 

@Override 
    public void onAnimationUpdate(ValueAnimator animation) { 
     // Gets the animated float fraction 
     float val = animation.getAnimatedFraction(); 

     // Gets the point at the fractional path length 
     PathMeasure pathMeasure = new PathMeasure(path, true); 
     pathMeasure.getPosTan(pathMeasure.getLength() * val, point, null); 

     // Sets view location to the above point 
     view.setX(point[0]); 
     view.setY(point[1]); 
    } 
}); 

類似:Android, move bitmap along a path?

+1

あなたの答えがどのように働くかを説明するために多くの時間を費やすことができれば、質問者はあなたのコードに簡単に従うことができます。 – SuperBiasedMan

+1

@SuperBiasedManフィードバックありがとう!コメントに説明が追加されました。 –

+0

ビューは元の位置に戻るため、 'pathMeasure.getLength()/ 2'を実行しなければなりませんでした。 – Rick

関連する問題