Scale up Item in RecyclerView to overlaps 2 adjacent items Android

前端 未结 4 2211
离开以前
离开以前 2020-12-14 20:58

I\'m using RecyclerView with GridLayoutManager. The goal I want to achieve is when I click on an item, It\'ll scale up and overlaps the adjacent items. Just like the picture

4条回答
  •  悲哀的现实
    2020-12-14 21:40

    You need to do it the old way you do with normal ViewGroups, overriding the draw order of children. This example forces the first view to always be drawn last - you need to customize for your use case.

    public TopForcingRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setChildrenDrawingOrderEnabled(true);
    }
    
    @Override protected int getChildDrawingOrder(int childCount, int i) {
        if (i >= childCount - 1) return 0; 
        //when asked for the last view to draw, answer ZERO
        else return i + 1;
        //when asked for the i-th view to draw, answer "the next one"
    }
    

    Pay attention to off by one errors.

提交回复
热议问题