2016-08-28 3 views
0

私は2つのビューを同時にアニメーション化する必要があるプロジェクトに取り組んでいます。クォート/ハーフ・サークルに続く2ビューの無限アニメーション

状態0:この2つのビューは、円のx1 = -Radius, y1 = 0/x2 = Radius, y2 = 0にあります。

状態1:彼らは円の上部中央に同時に移動し、(振り子のように)衝突する必要があります

状態2:彼らは、円の中央下部に同時に戻って、衝突しなければなりません同様

状態3 ... N:彼らは上部中央に行くべきではバックボトムセンターに行くと再び衝突し、その後衝突...

私はMULTを試してみましたArcAnimatorを含む複数のライブラリがありますが、どれもこれをサポートしていないようです。

enter image description here

それをする方法はありますか? XMLでのみ、またはプログラムでは本当に重要ではありません。

編集:

これは私がこれまで何をやったかである:

private void startAnimation() { 

    DisplayMetrics metrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics (metrics); 

    int width = metrics.widthPixels; 
    int height = metrics.heightPixels; 
    float scale = metrics.density; 

    float initLeftX   = leftBall.getX(); 
    float initLeftY   = leftBall.getY(); 
    float targetLeftX  = topHelperView.getX(); // helper view on top of circle. 
    float targetLeftY  = topHelperView.getY(); 

    float initRightX  = rightBall.getX(); 
    float initRightY  = rightBall.getY(); 
    float targetRightX  = topHelperView.getX(); 
    float targetRightY  = topHelperView.getY(); 

    AnimatorSet animSet  = new AnimatorSet(); 

    ObjectAnimator anim1 = ObjectAnimator.ofFloat (leftBall, "x", initLeftX, targetLeftX); 
    ObjectAnimator anim2 = ObjectAnimator.ofFloat (leftBall, "y", initLeftY, targetLeftY); 
    ObjectAnimator anim3 = ObjectAnimator.ofFloat (rightBall, "x", initRightX, targetRightX); 
    ObjectAnimator anim4 = ObjectAnimator.ofFloat (rightBall, "y", initRightY, targetRightY); 

    animSet.play (anim1).with (anim2).with (anim3).with (anim4); 

    animSet.setDuration (5000); 
    animSet.start(); 

} 

問題はアニメーションが直線的に進行し、外側の円の湾曲した経路に従わないということですが。そして、私は振り子衝突を実装するための概念を考えることはできません。

+0

面白いアイデアを。あなたはどれくらいあなた自身の上にいましたか?または、完全なソリューションで回答を期待していますか? –

+0

@ cricket_007:私の編集をチェックしてください。ありがとう。 –

答えて

0

このサンプルコードはいくつかの調整が必要ですが、私はそれはあなたを助けると信じて:

package com.pachacuti.bouncingball; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.DisplayMetrics; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationSet; 
import android.view.animation.RotateAnimation; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     DisplayMetrics displayMetrics = new DisplayMetrics(); 
     this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
     int windowHeight = displayMetrics.heightPixels; 
     int windowWidth = displayMetrics.widthPixels; 

     final RotateAnimation rAnimLeft1 = new RotateAnimation(0, 90, 
       Animation.ABSOLUTE, windowWidth/2, Animation.ABSOLUTE, 0); 
     rAnimLeft1.setDuration(4000); 

     final RotateAnimation rAnimLeft2 = new RotateAnimation(0, -180, 
       Animation.ABSOLUTE, windowWidth/2, Animation.ABSOLUTE, 0); 
     rAnimLeft2.setDuration(4000); 
     rAnimLeft2.setRepeatCount(-1); 
     rAnimLeft2.setRepeatMode(2); 

     final RotateAnimation rAnimRight1 = new RotateAnimation(0, -90, 
       Animation.ABSOLUTE, -windowWidth/2, Animation.ABSOLUTE, 0); 
     rAnimRight1.setDuration(4000); 

     final RotateAnimation rAnimRight2 = new RotateAnimation(0, 180, 
       Animation.ABSOLUTE, -windowWidth/2, Animation.ABSOLUTE, 0); 
     rAnimRight2.setDuration(4000); 
     rAnimRight2.setRepeatCount(-1); 
     rAnimRight2.setRepeatMode(2); 

     final View bleft = findViewById(R.id.bLeft); 
     AnimationSet animSetLeft = new AnimationSet(true); 
     animSetLeft.addAnimation(rAnimLeft1); 
     animSetLeft.addAnimation(rAnimLeft2); 
     bleft.startAnimation(animSetLeft); 

     final View bright = findViewById(R.id.bRight); 
     AnimationSet animSetRight = new AnimationSet(true); 
     animSetRight.addAnimation(rAnimRight1); 
     animSetRight.addAnimation(rAnimRight2); 
     bright.startAnimation(animSetRight); 
    } 

} 

とレイアウトファイル:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.moahh.bouncingball.MainActivity"> 

    <View 
     android:id="@+id/bLeft" 
     android:layout_width="10px" 
     android:layout_height="10px" 
     android:background="@color/colorAccent" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     /> 

    <View 
     android:id="@+id/bRight" 
     android:layout_width="10px" 
     android:layout_height="10px" 
     android:background="@color/colorAccent" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" 
     /> 
</RelativeLayout> 
関連する問題