我想在滚动到某个位置(例如:3)后显示一个视图(示例TextView
),所以我使用RecyclerView
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();
}
}
和
mRecyclerView.addItemDecoration(new HeaderItemDecoration());
我工作,但问题是TextView
如果我继续滚动,这将消失。绘制后如何使此视图始终可见?任何帮助或建议将不胜感激。