2017-06-16 1 views
0

コード:ここで下から始めるのではなく、固定された場所から画像を上下に移動するには?私は現在、使用しています

TranslateAnimation mAnimation = new TranslateAnimation(
      TranslateAnimation.ABSOLUTE, 0f, 
      TranslateAnimation.ABSOLUTE, 0f, 
      TranslateAnimation.RELATIVE_TO_PARENT, 0f, 
      TranslateAnimation.RELATIVE_TO_PARENT, 1.0f); 
    mAnimation.setDuration(2000); 
    mAnimation.setRepeatCount(-1); 
    mAnimation.setRepeatMode(Animation.REVERSE); 
    mAnimation.setInterpolator(new LinearInterpolator()); 
    imageView.setAnimation(mAnimation); 

result.(画像品質を無視し、私はそれを変更します)です。

イメージを水平中央に配置しました。フローティングアクションボタンに垂直に配置しました。私はそれがそこから始めることを望む。

また、オプションで、フェードインフェードアウトAlphaAnimationを作成しました。どちらを同期させるのですか? AlphaAnimationため

コード:

AlphaAnimation blinkAnimation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible 
    blinkAnimation.setDuration(1000); // duration - half a second 
    blinkAnimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate 
    blinkAnimation.setRepeatCount(5000); // Repeat animation infinitely 
    blinkAnimation.setRepeatMode(Animation.REVERSE); 

答えて

2

このお試しください:alphaAnimationと結合するには

TranslateAnimation mAnimation = new TranslateAnimation(
      TranslateAnimation.RELATIVE_TO_SELF, 0f, 
      TranslateAnimation.RELATIVE_TO_SELF, 0f, 
      TranslateAnimation.RELATIVE_TO_SELF, 0f, 
      TranslateAnimation.RELATIVE_TO_SELF, -1.0f); 
//Less up :  TranslateAnimation.RELATIVE_TO_SELF, -0.5f); 

を:

AlphaAnimation blinkAnimation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible 
    blinkAnimation.setDuration(1000); // duration - half a second 
    blinkAnimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate 
    blinkAnimation.setRepeatCount(5000); // Repeat animation infinitely 
    blinkAnimation.setRepeatMode(Animation.REVERSE); 

AnimationSet set = new AnimationSet(true); 
set.addAnimation(trAnimation); 
set.addAnimation(mAnimation); 
imageView.startAnimation(set) 
+0

おかげで、これは助けないが、今の画像ちょっと高すぎる、前にそれを止める方法?あるいは、 'TranslateAnimation'のパラメータを説明できたら、私は自分自身を試すことができます。 –

+0

前に停止したい場合は、TranslateAnimation.RELATIVE_TO_SELF、-1.0fを変更してください。 TranslateAnimation.RELATIVE_TO_SELF、-0.5f)に; –

+0

これは、ありがとうございます。 –

0

ここでフェードインのための詳細コードです|フェードインアウト、ムーブアップ|ムーブダウン

移動アップおよび移動ダウンイメージビューコード:

TranslateAnimation anim = new TranslateAnimation(
      TranslateAnimation.RELATIVE_TO_SELF, 0f, 
      TranslateAnimation.RELATIVE_TO_SELF, 0f, 
      TranslateAnimation.RELATIVE_TO_SELF, 0f, 
      TranslateAnimation.RELATIVE_TO_SELF, -1.0f); // this is distance of top and bottom form current positiong 

      anim.setDuration(2000); 
      anim.setRepeatCount(3); 
      anim.setRepeatMode(Animation.REVERSE); 
      downloadIV.startAnimation(anim); 

フェードイン、フェードアウト:

AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f); 
    anim.setDuration(500); 
    anim.setRepeatCount(4); 
    anim.setRepeatMode(Animation.REVERSE); 

    //anim.setFillAfter(true); 
    downloadIV.startAnimation(anim); 
関連する問題