1

リスト ビューで onFling イベントをアニメーション化したいと考えています。

アニメーションは正常に動作しますが、行が間違っています。

例えば:

  1. ListView の項目が 1 つだけの場合、アニメーションは期待どおりに機能します。
  2. 2 つの項目を持つ ListView: 最初の項目でジェスチャを行うと、2 番目の項目がアニメーション化され、その逆です。
  3. 3 つの項目を含む ListView: ジェスチャを使用すると、最初の項目で make se 最後の項目がアニメーション化され、2 番目の項目で 2 番目の項目がアニメーション化され (予想どおり)、最後の項目で最初の項目がアニメーション化されます。

コード:

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    int position = listView.pointToPosition(Math.round(e1.getX()),
            Math.round(e1.getY()));
    View row = listView.getChildAt(position);
    TranslateAnimation anim = null;
    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH || row == null)
        return true;
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
            && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF,1,Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0);
        this.handleSwipe.onHandleSwipeLeft(position);
    } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
            && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF,-1,Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0);
        this.handleSwipe.onHandleSwipeRight(position);
    }else{
        return true;
    }

    anim.setDuration(500);
    row.startAnimation(anim);
    return true;
}

OBS:

すでにデバッグしており、位置と行は常に正しいです。

私はAPIレベル7を使用しています。

コードはAndroid 4.2で正常に動作します

4

1 に答える 1

0

Guilherme、おそらくコード:

    int position = listView.pointToPosition(Math.round(e1.getX()),
        Math.round(e1.getY()));    

行 ID 3 が返されません。確認できますか?

于 2013-01-08T10:45:32.633 に答える