Android Vertical scrolling for ListView inside Horizontal scrollView
I have a custom ArrayAdapter for a listView which is inside a horizontal scrollView.The horizontal scrolling works fine but for vertical scrolling I had to do some hacks. I just want to know if its a good idea since listView is already optimized for vertical scrolling.? Is there a way to scroll without this hack ?
The hack basically is to capture touchEvent for scrollView(parent class) and propaga开发者_高级运维te the touchEvent to ListView.
scrolLView.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
lv.setSmoothScrollbarEnabled(true);
lv.dispatchTouchEvent(arg1);
}
});
This causes scrolling to happen and things work. I just want to know if there are certain more things i need to take in to account.
Thanks
Your horizontal scroll view is in parent class, so the touch event will be recognized only for the scroll view and not for the list view. So if you want the list view to scroll, the way you did is correct.
In addition to your code, I've modified it to where there is only a ScrollView and multiple ImageView items 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;
}
});
精彩评论