片段内的滚动视图根本不滚动

Scrollview inside fragment not scrolling at all

我在 tablayout 中使用了三个片段 activity。在片段中,我有 12 个编辑文本,所以我将它们放入 scrollview.But 滚动不起作用,我只能看到很少的编辑文本。

fragment.xml

 <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="1dp"
        android:background="#fffbfbfb"
        android:fillViewport="false"
        android:id="@+id/scrollView">

        <TableLayout

            android:id="@+id/tableLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:stretchColumns="0"
            android:background="#fffbfbfb">
     ........
</scrollview>

activity.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />


        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

如果您在协调器布局中使用滚动视图,而不是使用默认滚动视图,请尝试使用 NestedScrollView

在你的代码中试试这个,确保滚动视图只有一个 child

<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:fillViewport="true"
android:isScrollContainer="false"

xmlns:android="http://schemas.android.com/apk/res/android" >

如果还是不行就把table布局换成线性布局

好的,我在 fragment.java 文件中做了一件事:

scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                scrollView.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

现在 scrollview 工作正常,但 viewpager 已停止工作我的意思是我无法通过水平触摸更改片段,因为在将上述方法放入 fragment.java

之前它正在工作