传统ListView根据PaddingTop自定义实现下拉刷新,上拉加载。
在这个基础上,添加下拉时修改Title栏透明度渐变效果:
int firstVisibleItemPosition == 0
double scale = (double) 255 / (double) mBannerHeight;//Y轴偏移量对应透明度转换的比例
在onTouchEvent(MotionEvent ev)
的case MotionEvent.ACTION_MOVE:中
获取 int diffY = moveY - downY;//从按下到移动的距离
在判断 firstVisibleItemPosition == 0,且
int paddingTop = -headerViewHeight + (diffY / 2);//Y轴偏移量是head的两倍时展示刷新时,调用getAlpha();
private void getAlpha(int diffY, int paddingTop) {
int x = mTitleHeight - headerViewHeight;
int alpha = 0;
if( paddingTop > -headerViewHeight && paddingTop < x) {
int headViewDiffY = paddingTop + headerViewHeight;//头部View偏移量
alpha = (int) (scale * (headViewDiffY));
if (alpha > 255) {
alpha = 255;
}
} else {
alpha = 255;
}
Logger.i("commList" , "alpha: " + alpha);
//setAlpha();
}