我有一个垂直的自定义列表,垂直列表的每一项都包含一个水平的列表视图。当我水平滚动时,list也会垂直移动一点。这使得它对用户不太友好。是否可以在水平滚动时禁用垂直滚动。我正在使用
<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"
/>对于水平列表视图
发布于 2014-07-14 18:34:19
这个想法是为了禁用父listview来拦截触摸事件。这可能会起作用:
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;
}
});发布于 2015-05-20 13:09:13
最好的方法就是这样做。
将给定的代码放在您的水平列表视图onScroll方法上,它实际上是有效的
ViewParent view_parent = getParent();
if (view_parent != null)
{
view_parent.requestDisallowInterceptTouchEvent(true);
}https://stackoverflow.com/questions/24734226
复制相似问题