2011-11-19 13 views
2

xmlファイルでアニメーションを定義しようとしましたが、柔軟性が十分ではありません。どのように私はこれをコードで動作させることができるかに関するアイデア。TranslateAnimation - アニメーションの開始時に画像が消える

アニメーションが開始されると、画像が消えてから再び表示されます。本質的に、私が指を持ち上げると、画像が元の位置に戻ってゆっくりスライドする必要があります。これは何らかの理由で起こることではありません。

Javaコード:

chargeButton.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     int x_cord = (int) event.getRawX(); 
     int y_cord = (int) event.getRawY(); 

     switch (event.getActionMasked()){ 
      case MotionEvent.ACTION_DOWN: 
       break; 
      case MotionEvent.ACTION_MOVE: 
       chargeButton.setLayoutParams(setPosition(x_cord, false)); 
       break; 
      case MotionEvent.ACTION_UP: 
       int x_start = x_cord; 
       x_cord = 0; 
       slowMove(x_start, x_cord, false); 

       break; 
      default: 
       break; 
     } 
     return true; 
    } 
}); 


} 

public void slowMove(int x_start, int x_final, boolean pay) 
{ 
Animation transAnimation = new TranslateAnimation(x_start, x_final, 0, 0); 
transAnimation.setFillAfter(true); 
transAnimation.setDuration(1000); 
if (pay) 
    payButton.startAnimation(transAnimation); 
else 
{ 
    chargeButton.clearAnimation(); 
    chargeButton.startAnimation(transAnimation); 
} 
} 

私は本当に私が得ることができる任意の助けをいただければ幸いです。

答えて

1

自分のコード自体からfromXdeltaを変更したいと考えています。

なぜconstructorを使用していませんか?

public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 

fromXDelta Change in X coordinate to apply at the start of the animation 
toXDelta Change in X coordinate to apply at the end of the animation 
fromYDelta Change in Y coordinate to apply at the start of the animation 
toYDelta Change in Y coordinate to apply at the end of the animation 
+0

コンストラクタを使用することで完璧になります。しかし、コンストラクタを使用しようとすると、私のimageViewが完全に消えます。なぜこれが起こっているのか分かりません。 x_start、x_final、y_start、y_finalをintとして入力しています。これは問題だろうか?なぜこれが起こるのか知っていますか?ビューの絶対的な配置を使用するコンストラクタを通してtranslateImageの作業コードを持っていますか? – roro

+0

intは重要です。私はあなたのコードが見えるまでイメージが消える理由を言うことができません。ここには[動作例](http://iserveandroid.blogspot.com/2010/12/slide-up-down-translate.html) – Reno

+0

ちょっとリノ..私のコードを含めるように私の質問を更新しました。イメージが消える理由についてのアイデア? – roro

関連する問題