下面列出了android.widget.TextView#getTranslationY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull TextView child, @NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
if (target instanceof RecyclerView) {
RecyclerView list = (RecyclerView) target;
//列表第一个全部可见Item的位置
int pos = ((LinearLayoutManager) list.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
if (pos == 0 && pos < lastPosition) {
downReach = true;
}
if (canScroll(child, dy) && pos == 0) {
float finalY = child.getTranslationY() - dy;
if (finalY < -child.getHeight()) {
finalY = -child.getHeight();
upReach = true;
} else if (finalY > 0) {
finalY = 0;
}
child.setTranslationY(finalY);
consumed[1] = dy;
}
lastPosition = pos;
}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mGreenView1 = (TextView) findViewById(R.id.greenView1);
mGreenView1TranslationY = mGreenView1.getTranslationY();
mGreenColor = getResources().getColor(android.R.color.holo_green_light);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mGreenView1 = (TextView) findViewById(R.id.greenView1);
mGreenView1TranslationY = mGreenView1.getTranslationY();
mGreenColor = getResources().getColor(android.R.color.holo_green_light);
}