I have a gallery with images and when scroll horizontally, multiple images are scrolled instead of one.
Below is part of my code:
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
view = inflater.inflate(resourceid, null);
}
synchronized (view) {
TextView txtTitle = (TextView) view
.findViewById(R.id.txtCaption);
ImageList item = getItem(position);
ImageView ivImage = (ImageView) view.findViewById(R.id.ivImage);
ivImage.setScaleType(ScaleType.CENTER_INSIDE);
try {
ivImage.setImageBitmap(getBitmapFromAsset(item.imageUrl));
}
This solution works perfectly.
PS: You need to extends a Gallery.
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int kEvent =
e1.getX() < e2.getX() ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT;
onKeyDown(kEvent, null);
return true;
}