2012-04-18 17 views

risposta

9

Ho utilizzato Camera.setTranslate(x, 0, z) in drawChild, dove è stata modificata la posizione x per la virtualizzazione della rotazione e z per la sovrapposizione. Poi c'è stato un problema con la sovrapposizione, perché l'ultimo elemento era in cima e il primo sullo strato inferiore. Quindi, nel metodo onCreate() chiamato this.setChildrenDrawingOrderEnabled(true) e sostituito protected int getChildDrawingOrder (int childCount, int i) {} in cui è stato possibile modificare l'ordine per le righe centrali e successive. Questa idea è stata data da Renard, che mi ha suggerito in altri miei post circa la stessa cosa here.

mio getChildDrawingOrder (int, int) implementazione per ottenere la sovrapposizione ho bisogno:

@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; 

} 

Spero che questo post vi aiuterà qualcuno in futuro

Schermata è in realtà quasi lo stesso come ho detto nella mia interrogazione . Ho usato alpha, quindi gli elementi sovrapposto è un po 'see-through:

enter image description here

+0

@pengwang quale demo? intendi screenshot del risultato? –

+0

sì, hai ragione, puoi condividere il tuo screenshot del codice risultato – pengwang

+0

@PooLaS per favore dammi il link di preferenza o pubblica le tue lezioni per capire questa cosa da implementare. –

Problemi correlati