Android Scrollview无法在导航栏

时间:2016-06-24 10:19:28

标签: android navigation-drawer android-scrollview

我有一个Activity,其导航抽屉工作正常,但在抽屉后面ScrollView不起作用。

这是我的xml代码,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="4dp"
    tools:context="com.bala.beautytipstamil.Content">

    <WebView
        android:id="@+id/txtTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="15sp" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/include"
        android:layout_below="@+id/txtTitle">

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

            <ImageView
                android:id="@+id/imgContent"
                android:layout_width="match_parent"
                android:layout_height="150dp" />

            <WebView
                android:id="@+id/txtContent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
    </ScrollView>

    <include
        android:id="@+id/include"
        layout="@layout/buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/navList"
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:layout_gravity="left|start"
            android:background="#ffeeeeee" />
    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

请帮忙!

2 个答案:

答案 0 :(得分:1)

ScrollView置于DrawerLayout内,如下所示。只需复制并粘贴即可。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="4dp"
        tools:context="com.bala.beautytipstamil.Content">

        <WebView
            android:id="@+id/txtTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="15sp" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/include"
            android:layout_below="@+id/txtTitle">

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

                <ImageView
                    android:id="@+id/imgContent"
                    android:layout_width="match_parent"
                    android:layout_height="150dp" />

                <WebView
                    android:id="@+id/txtContent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>
        </ScrollView>

        <include
            android:id="@+id/include"
            layout="@layout/buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />


    </RelativeLayout>

    <ListView
        android:id="@+id/navList"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="#ffeeeeee" />


</android.support.v4.widget.DrawerLayout>

答案 1 :(得分:0)

public class VerticalScrollview extends ScrollView {

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

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

public VerticalScrollview(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:
            super.onTouchEvent(ev);
            break;

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

        case MotionEvent.ACTION_CANCEL:
            super.onTouchEvent(ev);
            break;

        case MotionEvent.ACTION_UP:
            return false;

        default: break;
    }

    return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    super.onTouchEvent(ev);
    return true;
}

}