7

scrollview 内に scrollview があります。xmlはこのようなものです

<RelativeLayout ....
    <ScrollView.....
         <RelativeLayout ....
           <Button.....
           <Button ....
           <ScrollView
             <RelativeLayout ....
                 ..........
               </RelativeLayout>
             </ScrollView>
         </RelativeLayout>
     </ScrollView>
 </RelativeLayout>

この2番目のスクロールビューでは、スムーズにスクロールしません。そのための解決策を与えることができます。私はインターネットで与えられた多くの解決策を試しましたが、うまくいきませんでした。

4

3 に答える 3

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;
}
});`
于 2013-07-16T08:40:47.233 に答える
0

私にとってはうまくいかなかったので、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;
                }
            });
        }
    }
}
于 2014-12-16T02:37:57.617 に答える