2011-07-27 6 views
2

私のカスタムViewGroupに問題があります。私は3つの子供たちを連続してレイアウトし、Scrollerを使用して子供の中にスクロールします。ユーザーのタッチ入力に基づいて、私は表示すべき子供を変更し、新しいレイアウトを要求する。それから私は新しい順序で子供たちをレイアウトします。しかし、1つの子供が以前のレイアウトで表示されたとき、子供はお互いの上に横たわっている。私は子供たちが正しい方法でレイアウトを取得していることを確認しました。古いレイアウトは削除されず、新しい子供は古いレイアウトの上に描画されるだけです。古いレイアウトがクリアされるようにする方法はありますか?ここでViewGroup onLayout問題

は私のコードです:

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    ... 
    case MotionEvent.ACTION_UP: 
     if(old != current) 
      this.requestLayout(); 
     else 
      this.scrollTo(getWidth(), 0); 
    ... 
} 

@Override 
protected void onLayout(boolean changed, int l, int t, int r, int b) { 
    // show current-1, current, current+1 
    int count = 0; 
    for(int i = 1; i >= -1; i--) { 
     // determine index of child 
     // the mod does a modulo 
     int index = mod(current-i, getChildCount()); 
     // position in row from left to right 
     this.getChildAt(index).layout(count*this.getWidth(), 0, (count+1)*this.getWidth(), height); 
     count++; 
    } 
    // scroll to middle view 
    this.scrollTo(getWidth(), 0); 
    ... 
} 

答えて

1

onLayout()の終わりにinvalidate()を呼び出すようにしてください。

関連する問題