android - RecyclerView onDrawOver view disappear after scroll -
i want display view (example textview
) on recyclerview
after scroll position (example: 3) use
public class headeritemdecoration extends recyclerview.itemdecoration { @override public void ondrawover(canvas c, recyclerview parent, recyclerview.state state) { super.ondrawover(c, parent, state); int topchildposition = parent.getchildadapterposition(parent.getchildat(0)); if(topchildposition == 3) { log.i("tag", "draw header"); textview textview = new textview(parent.getcontext()); textview.settext("bbdasdasd"); textview.setbackgroundcolor(color.red); textview.layout(0, 0, 100, 100); drawtext(c, textview); } } private void drawtext(canvas c, view header) { c.save(); c.translate(0, 0); header.draw(c); c.restore(); } }
and
mrecyclerview.additemdecoration(new headeritemdecoration());
i work problem textview
gone if continue scroll. how make view visible after draw it? or suggestion great appreciated.
just change if condition:
if(topchildposition == 3) { ... }
to:
if(topchildposition >= 3) { ... }
so view remain visible if continue scroll down.
if want remain visible if scroll top, add member variable remember if view shown, if it's shown, keep drawing it.
Comments
Post a Comment