I had a similar problem. The problem is that the ListView intercepts touch events from your gallery and changes the position of the view in its code block, which deals with the vertical scroll of the ListView. If only the Gallery first intercepted the touch event ... I consider this a mistake in the Android source, but in the meantime you can fix the unglazed scrolling by subclassing Gallery and use your subclass instead. This will do the trick:
public class BetterGallery extends Gallery { private boolean scrollingHorizontally = false; public BetterGallery(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public BetterGallery(Context context, AttributeSet attrs) { super(context, attrs); } public BetterGallery(Context context) { super(context); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { super.onInterceptTouchEvent(ev); return scrollingHorizontally; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { scrollingHorizontally = true; return super.onScroll(e1, e2, distanceX, distanceY); } @Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: scrollingHorizontally = false; } return super.onTouchEvent(event); } }
Also, install something similar in the action that implements the gallery:
ListView listView = (ListView) view.findViewById(R.id.users); listView.setAdapter(userListAdapter); listView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { galleryView.onTouchEvent(event); return false; } });
Finally, add onTouchEvent () to the activity itself:
@Override public boolean onTouchEvent(MotionEvent event) { return galleryView.onTouchEvent(event); }
One final note ... After fully implementing this method, I found that in terms of usability it was better to extend ViewAnimator with a special class, which I called AdaptableViewAnimator, which, of course, was associated with some adapters and embedding ListView inside it. It does not float like a ListView inside a gallery.
jkschneider
source share