我有静态ImageView,当我点击一个按钮时,它的内容会随机变化。 如何使图像滚动像这样:
public void changeImage() {
int pickedNumber = FunctionUtils.randomInRange(arrImgList.size());
Bitmap bmImg = BitmapFactory.decodeFile(arrImgList.get(pickedNumber));
img.setImageBitmap(bmImg);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (count < 30) {
changeImage();
count++;
}
}
}, 50);
}
我想在更改图片时添加效果:
Bitmap bmImg = BitmapFactory.decodeFile(arrImgList.get(pickedNumber));
img.setImageBitmap(bmImg);
答案 0 :(得分:1)
我使用Android Wheel: https://code.google.com/p/android-wheel/ 我的适配器:
private class SlotMachineAdapter extends AbstractWheelAdapter {
// Layout inflater
private Context context;
/**
* Constructor
*/
public SlotMachineAdapter(Context context) {
this.context = context;
}
@Override
public int getItemsCount() {
return arrImgList.size();
}
// Layout params for image view
final ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
ImageView img;
if (cachedView != null) {
img = (ImageView) cachedView;
} else {
img = new ImageView(context);
}
img.setLayoutParams(params);
Bitmap bitmap = BitmapFactory.decodeFile(arrImgList.get(index));
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, widthWheel, heightWheel, true);
bitmap.recycle();
img.setImageBitmap(scaled);
return img;
}
}