獲取Gridview從開(kāi)始到結(jié)束所經(jīng)過(guò)的距離梧却,滑動(dòng)結(jié)束后調(diào)用
private int getScrollOffset(){
//GridView行間距
int mVerticalSpacing = your-vertical-spacing-in-dp;
//item 偏移量
int mOffset = mVerticalSpacing;
//正值表示向上滑動(dòng),負(fù)值表示向下滑動(dòng)
//mScrollRows--滑動(dòng)前后經(jīng)過(guò)的行數(shù)
//mOldFirstVisiblePosition--滑動(dòng)前所顯示的第一個(gè)item位置
//numColumns--GridView 列數(shù)
int mScrollRows = (your-gridview.getFirstVisiblePosition()-mOldFirstVisiblePosition)/numColumns;
//當(dāng)前顯示的第一個(gè)item
View mFirstItem = container.getChildAt(0);
//item高度
int mItemHeight = mFirstItem.getHeight;
if(null!=mFirstItem){
mOffset -= mFirstItem.getTop();
}
return mScrollRows*mItemHeight+mOffset;
}