2017-05-04 7 views
0

こんにちは、スタンプコミュニティ、Androidのテキスト位置が永久に動作しない

テキストビューの位置を変更したいと思います。

私はいくつかの方法を試しましたが、すべての場合、ビューの位置は元の位置に戻されます。

私が試した方法で、すべてのこれらの方法については

// 1. way 
    someText.setX(newPositionX); 
    someText.setY(newPositionY); 

    // 2.way 
    someText.x(newPositionX).y(newPositionY).setDuration(0).start(); 

    // 3.way 
    someText.animate().x(newPositionX).y(newPositionY).setDuration(0).start(); 

    //4.way 
    ObjectAnimator objectAnimatorX= ObjectAnimator.ofFloat(someText, "translationX", oldPositionX, newPositionX); 
    ObjectAnimator objectAnimatorY= ObjectAnimator.ofFloat(someText, "translationY", oldPositionY, newPositionY); 
    objectAnimatorX.setDuration(0); 
    objectAnimatorX.start(); 
    objectAnimatorY.setDuration(0); 
    objectAnimatorY.start(); 

    // 5.way 
    ObjectAnimator animX = ObjectAnimator.ofFloat(someText, "x", newPositionX); 
    ObjectAnimator animY = ObjectAnimator.ofFloat(someText, "y", newPositionY); 
    AnimatorSet animSetXY = new AnimatorSet(); 
    animSetXY.playTogether(animX, animY); 
    animSetXY.start(); 

、それは元の場所にリセットされます。

しかし、私はonTouchイベントでアニメーション機能を使用しています。 someText.animate().x(newPositionX).y(newPositionY).setDuration(0).start();

元の座標に設定されていないため、変更は永続的です。これは私が欲しいものですが、タッチイベント、つまり他のいくつかのイベントを使用するコードの他の部分を使わずに、これを実行したいと思います。私はonTouchイベントを使用いけないとき、それは一時的なものでありながら、私はonTouchイベントを使用するときに変更を永続的であるのはなぜ

私の質問は

  1. ですか?
  2. テキストの位置を永久に設定するにはどうすればよいですか?

最後に私のxmlは、TextViewに

どういうわけか、私が固定されてい
`<TextView 
    android:id="@+id/latinBigTextView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="20dp" 

    android:background="@drawable/border_text" 
    android:text="Initial text " />` 

答えて

0

のために、このようなものです。私はまだ最高の結果を得ていませんが、永久に更新します。おそらく私の計算のためにおそらく、それは位置の更新が残っているようです。私は次のコードを使用しました:

TranslateAnimation anim = new TranslateAnimation(0, deltaX, 0, deltaY); 
    anim.setDuration(0); 
    anim.setFillAfter(true); 
    anim.setFillEnabled(true); 
    anim.setAnimationListener(new Animation.AnimationListener() 
    { 
     @Override 
     public void onAnimationStart(Animation animation) 
     { 
     } 
     @Override 
     public void onAnimationEnd(Animation animation) 
     { 
      int l = newPosX; 
      int t = newPosY; 
      int r = SomeText.getWidth() + newPosX; 
      int b = SomeText.getHeight() + newPosY; 
      latinText.layout(l, t, r, b); 
     } 
     @Override 
     public void onAnimationRepeat(Animation animation) 
     { 
     } 
    }); 
    latinText.startAnimation(anim); 

ここで、SomeTextは永久に動的に移動したいtextViewです。 DeltaXとDeltaYは、移動したいピクセルの量です。 (l、r、t、b)はビューの(左、上、右、下)を意味します。

同じ問題に直面した他の人々に役立つことを願っています。

しかし、私は最初の質問に対してまだ答えはありません。誰もが知っていると言うなら、私は非常に感謝します。

関連する問題