1

I googled my problem and read similar questions in stackoverflow but I dont solve any way.

I have a layout with coordinatorLayout (main.xml) and a fragment with relativeLayout (fragment.xml)

main.xml

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:paddingRight="16dp"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_weight="1">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:text="FRAGMENT TITLE"
                    android:textSize="20sp"
                    android:textColor="@color/colorWhite"
                    android:id="@+id/main_toolbar_title"
                    android:gravity="center_vertical" />
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:background="@color/colorWhite"
        android:layout_width="match_parent"
        android:layout_height="60dp" />
</android.support.design.widget.AppBarLayout>

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

fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#f3f3f3">

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

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

        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:contentPadding="1dp"
            card_view:cardCornerRadius="2dp">

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

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="66dp"
                    android:textAllCaps="false"
                    android:text="Button Title"
                    android:textSize="18sp"
                    android:textColor="#404040"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
    </LinearLayout>
</ScrollView>
</RelativeLayout>

As you have seen, I have more buttons in scrollView but not scrolling. The ui elements in view pager, I first thought it was because of view pager but I have test it test_fragment.xml, it works perfectly.

scrollView scrolls when I press and hold out of view pager (ex. My First Tab) and move finger up/down

test_fragment.xml

<android.support.design.widget.CoordinatorLayout
android:id="@+id/quickreturn_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

What is the problem?

Thanks in advance.

1 Answer 1

6

As your are working with AppBarLayout, it doesn't work with simple ScrollView. you should use NestedScrollview instead. and you have took your ScrollView inside RelativeLayout that's not necessary. try again with removing that RelativeLayout by using NestedScrollView.

I guess it will help.

Sign up to request clarification or add additional context in comments.

3 Comments

Glad to hear that.. :)
Helped me fixing the issue, It was difficult to find the issue(AppBarLayout with scrollview), how did you identify this issue :)?
@Amritesh i am glad it helped.and about that issue, android Dev site has all Answers if we know know to find ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.