Parsania Hardik Parsania Hardik - 3 months ago 27
Android Question

Scrollview inside fragment not scrolling at all

I am using three fragments in one activity with tablayout. In fragment I have 12 edittext so I put them into the scrollview.But scrolling is not working and I can see only few edittexts.

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>

Answer

Ok I did one thing in fragment.java file:

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

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

Now scrollview is working fine but viewpager has stopped working I mean I am not able to change fragment by horizontally touch as it was working before putting above method in fragment.java