创建图片ID数组:
private int[] imgIdArray = {
R.drawable.f143,
R.drawable.f144,
R.drawable.f145,
R.drawable.f146,
};
以下是获取当前图片ID代码:
“上一张” 按钮代码:
//图片不可循环,到最后一张不能再继续下一张
currImgId = (currImgId == 0) ? 0 : --currImgId;
//图片可以循环,到最后一张可以跳回第一张
currImgId = (currImgId - 1 + imgIdArray.length) % imgIdArray.length;
img.setImageResource(imgIdArray[currImgId]);
下一张代码:
//图片不可循环,到最后一张不能再继续下一张
currImgId = (currImgId == (imgIdArray.length-1)) ? (imgIdArray.length - 1) : ++currImgId;
//图片可以循环,到最后一张可以跳回第一张
currImgId = (currImgId + 1) % imgIdArray.length;
img.setImageResource(imgIdArray[currImgId]);
Android 点击按钮上下翻页图片
最新推荐文章于 2022-11-06 21:18:44 发布