Xml Scrollview不起作用

时间:2015-11-25 06:02:28

标签: android xml scrollview

我已尝试过滚动此xml属性的所有可能方法,但它根本不起作用。请告诉我使用它的方法和我的父布局抽屉布局。 谢谢

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <include
                    android:id="@+id/hmebar"
                    layout="@layout/toolbar" />
                <!--<include layout="@layout/home_screen"/>-->

                <include layout="@layout/banner" />

                <include layout="@layout/featured_products" />
            </LinearLayout>
    </ScrollView>

1 个答案:

答案 0 :(得分:0)

将您的scrollView自定义为:

public class MyScrollView extends ScrollView {

    public MyScrollView(Context context) {
        super(context);
    }

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

    public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action)
        {
            case MotionEvent.ACTION_DOWN:
                Log.i("MyScrollView", "onInterceptTouchEvent: DOWN super false" );
                super.onTouchEvent(ev);
                break;

            case MotionEvent.ACTION_MOVE:
                return false; // redirect MotionEvents to ourself

            case MotionEvent.ACTION_CANCEL:
                Log.i("MyScrollView", "onInterceptTouchEvent: CANCEL super false");
                super.onTouchEvent(ev);
                break;

            case MotionEvent.ACTION_UP:
                Log.i("MyScrollView", "onInterceptTouchEvent: UP super false" );
                return false;

            default: Log.i("MyScrollView", "onInterceptTouchEvent: " + action ); break;
        }

        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        super.onTouchEvent(ev);
        Log.i("MyScrollView", "onTouchEvent. action: " + ev.getAction() );
        return true;
    }
}

在布局中使用它。