其实网上有很多类似的,实现起来也很简单。
1.拿到滑动视图的滑动距离
public int getScrollY() { View c = mLv.getChildAt(0); if (c == null) { return 0; } int firstVisiblePosition = mLv.getFirstVisiblePosition(); int top = c.getTop(); return -top + firstVisiblePosition * c.getHeight() ; }
2.设置色值渐变
int h = getScrollY(); float scale = (float) h / firstView.getHeight(); mRlTltle.setAlpha(scale);可以根据设计的要求进一步优化