android - Disable central item overlap in RecyclerView -
i have horizontal recyclerview images.
when scroll left, have image order this.
when scroll right, have order this.
i need set central image on top, above left , right ones. how it?
i overrided getchilddrawingorder
method:
@override protected int getchilddrawingorder(int childcount, int i) { int centerchild; //find center row if ((childcount % 2) == 0) { //even childcount number centerchild = childcount / 2; // if childcount 8 (actualy 0 - 7), 4 , 4-1 = 3 in centre. int othercenterchild = centerchild - 1; //which more in center? view child = this.getchildat(centerchild); final int left = child.getleft(); final int right = child.getright(); //if row goes through center final int absparentcenterx = getleft() + getwidth() / 2; //log.i("even", + " " + (childcount - 1) + ", while centerchild = " + centerchild); if ((left < absparentcenterx) && (right > absparentcenterx)) { //this child in center line, last //centerchild in center, no need change } else { centerchild = othercenterchild; } } else {//not - done centerchild = childcount / 2; //log.i("not even", + " " + (childcount - 1) + ", while centerchild = " + centerchild); } int rez; //find drawindex centerchild if (i > centerchild) { //below center rez = (childcount - 1) - + centerchild; } else if (i == centerchild) { //center row //draw last rez = childcount - 1; } else { //above center - draw // < centerchild rez = i; } //log.i("return", "" + rez); return rez; }
also set
setchildrendrawingorderenabled(true);
full code here.
fixed adding viewcompat.settranslationz(view, translationz);
protected final void updateviews() { (int = 0; < getchildcount(); i++) { view child = getchildat(i); //setmarginsforchild(child); if (mappearanimationisworking) child.setalpha(0); else child.setalpha(1); if (mscaleunfocusedviews && !mappearanimationisworking) { float scale = computescale(child); child.settranslationy(-getmeasuredheight() * (1 - scalefactor) / 2); viewcompat.settranslationz(child, -getpercentagefromcenter(child)); child.setscalex(scale * scalefactor * innerscale); child.setscaley(scale * scalefactor * innerscale); } } }
getchilddrawingorder
, setchildrendrawingorderenabled
can removed.
Comments
Post a Comment