Android Vertical scroll for ListView inside horizontal scrollView

I have a custom ArrayAdapter for a listView that sits inside a horizontal scrollView. Horizontal scrolling works fine, but for vertical scrolling I had to do some hacks. I just want to know if this is a good idea, since listView is already optimized for vertical scrolling.? Is there a way to scroll without this hack?

Basically hack touchEvent capture for scrollView (parent class) and extend touchEvent to ListView.

scrolLView.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View arg0, MotionEvent arg1) { lv.setSmoothScrollbarEnabled(true); lv.dispatchTouchEvent(arg1); } }); 

This causes a scroll and everything works. I just want to know if there are some more things that I need to register.

thanks

+6
source share
2 answers

The horizontal scroll view is in the parent class, so the touch event will be recognized only for viewing the scroll, and not for the list view. Therefore, if you want the scroll of the list to scroll, then how you did it is correct.

+3
source

In addition to your code, I changed it where only ScrollView and a few ImageView elements are inside.

 ScrollView _sv = (ScrollView)findViewById(R.id.scroller); _sv.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { _iv.setScrollContainer(true); _iv.dispatchTouchEvent(event); return false; } }); 
+1
source

Source: https://habr.com/ru/post/893213/


All Articles