Android - ListView inside gallery makes scrolling not smooth

I implemented the gallery, and inside it I have many lists from left to right. For some reason, Gallery works great with all views, but not with the list. When viewing the list when the gallery scrolls, sometimes I get small jumps.

Does anyone have an idea how to solve this?

some notes. The gallery uses an adapter to find out what to show, and then a list is created based on the adapter

thanks

+6
android
source share
4 answers

Scrollable items inside other scrollable items have problems. I am not surprised that this does not work.

+2
source share

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.

+8
source share

I had the same problem. And the solution is less than easy.

    • Set the view mode not in focus mode in touch mode.

    listView.setFocusableInTouchMode(false);

    • If you need focus, call it from the onItemSelected listener.
  • Use OnInterceptTouchEvent to receive sensory events from your child. And make some changes to onScroll and onTouchEvent from your gallery

     OnItemSelectedListener mOnItemSelected = new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { view.requestFocusFromTouch(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { onTouchEvent(ev); return scrollingHorizontally; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if(Math.abs(distanceX)>Math.abs(distanceY) || scrollingHorizontally == true){ scrollingHorizontally = true; super.onScroll(e1, e2, distanceX, distanceY); } return scrollingHorizontally; } @Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: scrollingHorizontally = false; break; default: break; } super.onTouchEvent(event); return scrollingHorizontally; } 
+1
source share

It worked for me

 listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); 
+1
source share

All Articles