ng2b30
ng2b30

Reputation: 351

scrollview with recyclerview in fragment

This is the fragment that I put in the viewPager

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_own_product_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/profile_bg"
tools:context="fyp.hkust.facet.fragment.OwnProductFragment">

<android.support.v7.widget.RecyclerView
    android:id="@+id/ownproductlist"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentStart="true"
    android:padding="5dp">

</android.support.v7.widget.RecyclerView>


<com.melnykov.fab.FloatingActionButton
    android:id="@+id/add_product_fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_margin="16dp"
    android:elevation="6dp"
    android:src="@mipmap/ic_plus_white_36dp"
    fab:fab_colorNormal="@color/colorPrimary"
    fab:fab_colorPressed="@color/primary_pressed"
    fab:fab_colorRipple="@color/ripple"
    fab:fab_shadow="true" />

The following is the activity

Updated:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">


<!-- your content layout -->
<LinearLayout
    android:id="@+id/profile_linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:elevation="0dp" />

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/profile_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <RelativeLayout
            android:id="@+id/activity_profile"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/profile_bg"
            tools:context="fyp.hkust.facet.activity.ProfileActivity">

            <RelativeLayout
                android:id="@+id/profile_layout"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:orientation="vertical"
                android:weightSum="1">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/profile_picture"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_marginBottom="25dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="25dp"
                    android:elevation="6dp"
                    android:src="@mipmap/app_icon" />

                <Button
                    android:id="@+id/btn_edit"
                    android:layout_width="60dp"
                    android:layout_height="35dp"
                    android:layout_alignBottom="@+id/profile_email"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="20dp"
                    android:adjustViewBounds="true"
                    android:background="@drawable/border_button_no_bg"
                    android:clickable="true"
                    android:contextClickable="true"
                    android:scaleType="fitCenter"
                    android:text="@string/edit_btn_text"
                    android:textColor="@color/font_color_pirmary" />

                <TextView
                    android:id="@+id/profile_username"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="47dp"
                    android:layout_toEndOf="@+id/profile_picture"
                    android:layout_toStartOf="@+id/btn_edit"
                    android:text="@string/profile_username"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/profile_email"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/profile_username"
                    android:layout_toEndOf="@+id/profile_picture"
                    android:layout_toStartOf="@+id/btn_edit"
                    android:paddingLeft="20dp"
                    android:paddingTop="10dp"
                    android:text="@string/profile_email"
                    android:textColor="@color/profile_email_text_color"
                    android:textSize="10sp" />
            </RelativeLayout>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/profile_layout"
                android:background="@color/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/white"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/grey_title" />

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

        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

How can I make it to let me scroll the whole view instead of scrolling only in the recycler view like instragram? Thank you.

Upvotes: 0

Views: 888

Answers (2)

mnp343
mnp343

Reputation: 329

Use NestedScrollview Instead of scrollview.

You can enable / disable recyclerview's nested scrolling feature according to you need.

Scroll view doesn't support nested scrolling. Where as nested scroll view will give you what you need.

You should try following this hierarchy

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="192dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            app:contentScrim="@color/action_bar"
            app:expandedTitleGravity="right"
            app:layout_scrollFlags="scroll|enterAlways">

            <RelativeLayout
                android:id="@+id/app_images_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp"
                app:layout_collapseMode="parallax">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="below will be your elements" />

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/accent"
                    app:tabGravity="fill"
                    app:tabIndicatorHeight="2dp"
                    app:tabMode="fixed" />
            </RelativeLayout>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <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.CoordinatorLayout>

Upvotes: 1

Prabha Karan
Prabha Karan

Reputation: 1319

Change this ,at the end of the xml layout close the ScrollView .Place it below the Relative layout.

     <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/profile_scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:id="@+id/activity_profile"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/profile_bg"
        tools:context="fyp.hkust.facet.activity.ProfileActivity">

        <RelativeLayout
            android:id="@+id/profile_layout"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:orientation="vertical"
            android:weightSum="1">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_picture"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginBottom="25dp"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="25dp"
                android:elevation="6dp"
                android:src="@mipmap/app_icon" />

            <Button
                android:id="@+id/btn_edit"
                android:layout_width="60dp"
                android:layout_height="35dp"
                android:layout_alignBottom="@+id/profile_email"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="20dp"
                android:adjustViewBounds="true"
                android:background="@drawable/border_button_no_bg"
                android:clickable="true"
                android:contextClickable="true"
                android:scaleType="fitCenter"
                android:text="@string/edit_btn_text"
                android:textColor="@color/font_color_pirmary" />

            <TextView
                android:id="@+id/profile_username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="47dp"
                android:layout_toEndOf="@+id/profile_picture"
                android:layout_toStartOf="@+id/btn_edit"
                android:text="@string/profile_username"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/profile_email"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/profile_username"
                android:layout_toEndOf="@+id/profile_picture"
                android:layout_toStartOf="@+id/btn_edit"
                android:paddingLeft="20dp"
                android:paddingTop="10dp"
                android:text="@string/profile_email"
                android:textColor="@color/profile_email_text_color"
                android:textSize="10sp" />
        </RelativeLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_layout"
            android:background="@color/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/white"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/white"
            app:tabTextColor="@color/grey_title" />

        <LinearLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tabs"
            android:orientation="vertical">

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

        </LinearLayout>

    </RelativeLayout>
</ScrollView>

Upvotes: 0

Related Questions