我知道我们可以在两个滚动视图中使用touchlisteners
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG, "PARENT TOUCH");
findViewById(R.id.child_scroll).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG, "CHILD TOUCH");
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
我面临的是我的子滚动视图不是父滚动视图的直接子项.这v.getParent()不起作用,当我触摸并尝试滚动我的子滚动视图时,整个主滚动滚动.
我的滚动视图在我的布局中的位置(视图是动态创建的,因此我需要使用这么多布局)
linearLayout
ParentscrollView(0)
linearLayout(0)
relativeLayout(0)
TextView(0)
relativeLayout(1)
childScrollView(0)
Run Code Online (Sandbox Code Playgroud)
需要帮助.谢谢.!!
小智 6
是不是findViewById()父滚动视图id不工作?
childScrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG, "CHILD TOUCH");
// Disallow the touch request for parent scroll on touch of child view
findViewById(parentLayouttId).requestDisallowInterceptTouchEvent(true);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2704 次 |
| 最近记录: |