2016-09-14 3 views
1

ImageViewのアニメーションを画面の左から右に実行したい場合は、画面の50%に達したら戻ってきます。マイXML左から右にアニメーターを設定し、複数の画面を逆にする方法

<?xml version="1.0" encoding="utf-8"?> 
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" 

    android:duration="1000" 
    android:propertyName="x" 
    android:repeatMode="reverse" 
    android:repeatCount="1" 
    android:valueFrom="0" 
    android:valueTo="250" > 
</objectAnimator> 

私のアプリケーションは、自分の携帯電話にも走ったが、それは小さなまたは大きな電話で実行したとき、それがうまく実行されませんでした。 私はObjectAnimatorを使いたいと思いますし、私のアプリケーションの最小SDK APIは13です。誰が助けてくれるの?前もって感謝します。

答えて

0

より良い構造のために、動的なアプローチが

まず、画面の半分

Display display = getWindowManager().getDefaultDisplay(); 
    Point point=new Point(); 
    display.getSize(point); 
    final int width = point.x; // screen width 
    final float halfW = width/2.0f; // half the width or to any value required,global to class 
    ObjectAnimator lftToRgt,rgtToLft; // global to class 

    // initialize the view in onCreate 
    imageView = (ImageView) findViewById(R.id.imageButtontest); 

    // set the click listener 
    imageView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
       anim();// call to animate 
     } 
    }); 

は、あなたのクラスに以下の機能を追加し、楽しむ測定するために、画面の幅を計算し、表示画面幅を使用するお勧めします。

void anim(){ 
    // translationX to move object along x axis 
    // next values are position value 
    lftToRgt = ObjectAnimator.ofFloat(imageView,"translationX",0f,halfW) 
      .setDuration(700); // to animate left to right 
    rgtToLft = ObjectAnimator.ofFloat(imageView,"translationX",halfW,0f) 
      .setDuration(700); // to animate right to left 

    AnimatorSet s = new AnimatorSet();//required to set the sequence 
    s.play(lftToRgt).before(rgtToLft); // manage sequence 
    s.start(); // play the animation 
} 

事前に完全Code Snippet

+0

感謝をチェックしてください。しかし、私はAPI 13でobjectAnimatorと私のアプリケーションを使いたいと思っています。 –

+0

@KhoaMadridistaあなたはそれ以前に言っておくべきです –

+0

申し訳ありません。それは私のせいです。私は私の質問を編集しました –

関連する問題