0

I am working on a reader app in which i have a layout containing ViewPager. In this ViewPager. This ViewPager contains Fragment whose layout file contains a ScrollView. This ScrollView is scrolling correctly in most of the devices but on a device its not scrolling correctly. Actually on application launch, ScrollView is scrolling but after viewpager is swiped, scrollview's scrolling stops working. I can't understand why this is happening only on one device. ViewPager Layout is below:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:background="@color/holo_blue_light"
        android:orientation="horizontal"
        android:weightSum="1">

        <ImageView
            android:id="@+id/back_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.1"
            android:src="@drawable/left_arrow" />

        <TextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.7"
            android:gravity="center"
            android:text="Half Girlfriend"
            android:textColor="#000"
            android:textSize="18sp" />


        <ImageView
            android:id="@+id/visible"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.1"
            android:src="@drawable/hide" />

        <ImageView
            android:id="@+id/settings"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.1"
            android:src="@drawable/menu_x" />

    </LinearLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/page_status"
        android:layout_below="@+id/header"
        android:onClick="clickViewpager" />

    <TextView
        android:id="@+id/toast"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/page_status"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="40dp"
        android:background="@drawable/oval_border"
        android:padding="12dp"
        android:textSize="20sp"
        android:text="285"
        android:textColor="#fff" />

    <RelativeLayout
        android:id="@+id/page_status"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/bottom_bar_color"
        android:padding="10dp">

        <SeekBar
            android:id="@+id/page_level"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="283" />

        <RelativeLayout
            android:id="@+id/pages_col"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/page_level"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp">

            <TextView
                android:id="@+id/dynamic_no"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="25"
                android:textColor="#000" />

            <TextView
                android:id="@+id/of"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_toRightOf="@+id/dynamic_no"
                android:text="of"
                android:textColor="#000" />

            <TextView
                android:id="@+id/static_no"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_toRightOf="@+id/of"
                android:text="284"
                android:textColor="#000" />

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

This is the Fragment's layout:

<ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <RelativeLayout
            android:id="@+id/relative"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:descendantFocusability="blocksDescendants">

            <TextView
                android:id="@+id/getcontent"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:layout_margin="10dp"
                android:gravity="fill_horizontal|fill_vertical"
                android:textColor="#000" />

            <TextView
                android:id="@+id/page"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/getcontent"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:text="1"
                android:textColor="#000"
                android:textSize="14sp"
                android:visibility="gone" />


        </RelativeLayout>

    </ScrollView>
Itava
  • 45
  • 8

1 Answers1

0

I found the solution, there is nothing wrong with the code. Actually i was adding page transformer on Viewpager as

mPager.setPageTransformer(true, new ZoomOutPageTransformer());

but it does not work correctly in some android versions as solved in this post. It also not working correctly in Lollipop 5.1 and 5.1.1 so one can check for this also:

 if (Build.VERSION.SDK_INT != Build.VERSION_CODES.LOLLIPOP || Build.VERSION.SDK_INT != Build.VERSION_CODES.LOLLIPOP_MR1){
        mPager.setPageTransformer(true, new ZoomOutPageTransformer());
    }

If someone has a better solution then this, then please post. I hope my solution help someone. Thanks to all for contribution.

Itava
  • 45
  • 8