2012-04-18 11 views

Odpowiedz

9

Użyłem Camera.setTranslate(x, 0, z) w drawChild, gdzie zmieniono pozycję x dla wirtualizacji rotacji i z dla nakładania się. Potem pojawił się problem z nakładaniem, ponieważ ostatni element był na górze, a pierwszy na dolnej. Tak więc w metodzie onCreate() nazwano this.setChildrenDrawingOrderEnabled(true) i zmieniono protected int getChildDrawingOrder (int childCount, int i) {}, gdzie mogłem zmienić kolejność dla średnich i późniejszych rzędów. Pomysł ten został podany przez Renarda, który zasugerował mi w innym moim poście o prawie tym samym here.

My getChildDrawingOrder (int, int) realizacja aby nakładających muszę:

@Override 
protected int getChildDrawingOrder (int childCount, int i) { 
    int centerChild = 0; 
    //find center row 
    if ((childCount % 2) == 0) { //even childCount number 
     centerChild = childCount/2; // if childCount 8 (actualy 0 - 7), then 4 and 4-1 = 3 is in centre.  
     int otherCenterChild = centerChild - 1; 
     //Which more in center? 
     View child = this.getChildAt(centerChild); 
     final int top = child.getTop(); 
     final int bottom = child.getBottom(); 
     //if this row goes through center then this 
     final int absParentCenterY = getTop() + getHeight()/2; 
     //Log.i("even", i + " from " + (childCount - 1) + ", while centerChild = " + centerChild); 
     if ((top < absParentCenterY) && (bottom > absParentCenterY)) { 
      //this child is in center line, so it is last 
      //centerChild is in center, no need to change 
     } else { 
      centerChild = otherCenterChild; 
     } 
    } 
    else {//not even - done 
     centerChild = childCount/2; 
     //Log.i("not even", i + " from " + (childCount - 1) + ", while centerChild = " + centerChild); 
    } 

    int rez = i; 
    //find drawIndex by centerChild 
    if (i > centerChild) { 
     //below center 
     rez = (childCount - 1) - i + centerChild; 
    } else if (i == centerChild) { 
     //center row 
     //draw it last 
     rez = childCount - 1; 
    } else { 
     //above center - draw as always 
     // i < centerChild 
     rez = i; 
    } 
    //Log.i("return", "" + rez); 
    return rez; 

} 

Mam nadzieję, że ten post pomoże komuś w przyszłości

Screenshot jest faktycznie prawie taka sama, jak już wspomniałem w moim pytaniu . Kiedyś alfa, więc nakładka przedmiotów jest nieco przezroczyste:

enter image description here

+0

@pengwang what demo? masz na myśli zrzut ekranu wyniku? –

+0

tak, masz rację, możesz udostępnić zrzut ekranu z kodem wyniku – pengwang

+0

@PooLaS proszę podać link preferencji lub opublikuj swoje klasy, aby zrozumieć tę rzecz do wykonania. –