1. 程式人生 > >Android GridView顯示一行,左右滑動

Android GridView顯示一行,左右滑動

 點選左右箭頭實現滑動翻頁的效果

private int mScrollMaxDistance = 3;
private int mScrollDistance = 0;

case R.id.leftArrow:
	if (mScrollDistance > 0) {
		mScrollDistance -= 1;
		mScrollView.smoothScrollTo(
			mScrollView.getWidth() * mScrollDistance, 0);
	}
	break;
case R.id.rightArrow:
	if (mScrollDistance < mScrollMaxDistance) {
		mScrollDistance += 1;
		mScrollView.smoothScrollTo(
			mScrollView.getWidth() * mScrollDistance, 0);
	}
	break;