当用户在android中水平滚动时禁用垂直滚动
我有一个垂直自定义列表,每个垂直列表项都包含一个水平列表视图。当我水平滚动时,列表也会垂直移动。这使得它对用户不那么友好。我可以在水平滚动时禁用垂直滚动吗。我正在使用当用户在android中水平滚动时禁用垂直滚动,android,scroll,custom-lists,horizontallist,Android,Scroll,Custom Lists,Horizontallist,我有一个垂直自定义列表,每个垂直列表项都包含一个水平列表视图。当我水平滚动时,列表也会垂直移动。这使得它对用户不那么友好。我可以在水平滚动时禁用垂直滚动吗。我正在使用 <com.devsmart.android.ui.HorizontalListView android:id="@+id/hlistview" android:layout_width="match_parent" android:layout_height="155dp"
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/hlistview"
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_margin="6dp"
android:background="#fff"
android:fitsSystemWindows="true"
/>
对于水平列表视图的想法是禁用父列表视图以拦截触摸事件。这可能会奏效:
HorizontalListView hv = (HorizontalListView)findViewById(R.id.hlistview);
hv.setOnTouchListener(new ListView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ListView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ListView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle HorizontalScrollView touch events.
v.onTouchEvent(event);
return true;
}
});
参考资料:最好的方法
将给定的代码放在水平listview onScroll方法上,使其工作正常
ViewParent view_parent = getParent();
if (view_parent != null)
{
view_parent.requestDisallowInterceptTouchEvent(true);
}
嗨,试一下下面的答案。它可以工作,但当开始从HorizontalListView区域上下滑动时,HLV只会滚动。如果你有其他的解决方法,请分享。为什么不试试呢?