在android问题中的scrollview内的Scrollview

Nit*_*lal 7 android

我在scrollview中有一个scrollview.xml是这样的

<RelativeLayout ....
    <ScrollView.....
         <RelativeLayout ....
           <Button.....
           <Button ....
           <ScrollView
             <RelativeLayout ....
                 ..........
               </RelativeLayout>
             </ScrollView>
         </RelativeLayout>
     </ScrollView>
 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在第二个滚动视图中不能平滑滚动.可以为此提供解决方案.我在互联网上尝试了很多解决方案但没有工作.

小智 21

试试这个代码.它对我有用

 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;
}
});`
Run Code Online (Sandbox Code Playgroud)


Tyl*_*vis 7

另一种解决方案是将此类用作父类

public class NoInterceptScrollView extends ScrollView {

    public NoInterceptScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }

}
Run Code Online (Sandbox Code Playgroud)