我在滚动视图中有一个滚动视图。xml是这样的
<RelativeLayout ....
<ScrollView.....
<RelativeLayout ....
<Button.....
<Button ....
<ScrollView
<RelativeLayout ....
..........
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>在此第二个滚动视图中滚动不流畅。可以给出一个解决方案。我尝试了互联网上给出的许多解决方案,但都不起作用。
发布于 2013-07-16 16:40:47
试试这段代码。它正在为我工作。
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});`发布于 2014-05-28 06:15:43
另一种解决方案是将此类用作父类。
public class NoInterceptScrollView extends ScrollView {
public NoInterceptScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}
}发布于 2014-12-16 10:37:58
我不得不改进Deepthi的解决方案,因为它对我不起作用;我猜是因为我的孩子的滚动视图充满了视图(我的意思是说,孩子的视图使用了所有的滚动视图绘图空间)。为了使其具有完整的功能,我还必须在触摸子滚动视图内的所有子视图时禁止对父滚动的触摸请求:
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});`
childScrollviewRecursiveLoopChildren(parentScrollView, childScrollView);
public void childScrollviewRecursiveLoopChildren(final ScrollView parentScrollView, View parent) {
for (int i = ((ViewGroup) parent).getChildCount() - 1; i >= 0; i--) {
final View child = ((ViewGroup) parent).getChildAt(i);
if (child instanceof ViewGroup) {
childScrollviewRecursiveLoopChildren(parentScrollView, (ViewGroup) child);
} else {
child.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event)
{
// Disallow the touch request for parent scroll on touch of
// child view
parentScrollView.requestDisallowInterceptTouchEvent(true);
return false;
}
});
}
}
}https://stackoverflow.com/questions/17671123
复制相似问题