一,view.getLocalVisibleRect(rect);以目标view的左上角为参考系;
view.getGlobalVisibleRect(rect);以屏幕的左上角为参考系;
二,在recycler的一个item中,写了一个textview,滑动recyclerview使textview从可见到不可见,测试代码如下:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
View viewByPosition = layoutManager.findViewByPosition(0);
RecyclerView.ViewHolder childViewHolder = recyclerView.getChildViewHolder(viewByPosition);
if (childViewHolder instanceof MyViweHolder) {
Rect r = new Rect();
boolean localVisibleRect1 = ((MyViweHolder) childViewHolder).tvNumber.getLocalVisib