ShamylZakariya / StickyHeaders

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.
MIT License
1.4k stars 185 forks source link

use inside NestedScrollView #36

Closed MohammadRezaei92 closed 7 years ago

MohammadRezaei92 commented 7 years ago

my xml layout is: `<android.support.v4.widget.NestedScrollView 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:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:fillViewport="true" tools:showIn="@layout/fragment_product_details">

<LinearLayout
    android:id="@+id/content_product_details"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lay_product_name"
        app:cardElevation="1dp"
        app:cardCornerRadius="0dp"
        app:cardUseCompatPadding="false"
        app:cardPreventCornerOverlap="false"
        android:layout_marginBottom="2dp"
        app:contentPadding="2dp">

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center|left"
                    android:layout_weight="1">

                    <ImageButton
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_margin="8dp"
                        android:id="@+id/btn_share"
                        style="@style/Widget.AppCompat.Button.Borderless"
                        android:tint="@color/textSecondary"
                        app:srcCompat="@drawable/ic_share" />

                    <ImageButton
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_margin="8dp"
                        android:id="@+id/btn_favorite"
                        android:tint="@color/textSecondary"
                        style="@style/Widget.AppCompat.Button.Borderless"
                        app:srcCompat="@drawable/ic_favorite" />

                </LinearLayout>

                <com.iarcuschin.simpleratingbar.SimpleRatingBar
                    android:layout_width="wrap_content"
                    android:id="@+id/comment_rate"
                    app:srb_gravity="right"
                    app:srb_numberOfStars="5"
                    app:srb_stepSize="0.5"
                    app:srb_rating="0"
                    app:srb_starCornerRadius="0"
                    app:srb_starBorderWidth="1"
                    app:srb_borderColor="@color/divider_color"
                    app:srb_fillColor="@color/rate_fill_color"
                    android:layout_height="25dp" />

            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="?android:attr/textColorPrimary"
                android:id="@+id/txt_product_name"
                android:textSize="18dp"
                android:layout_margin="8dp"
                android:gravity="right"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="?android:attr/textColorSecondary"
                android:textSize="16sp"
                android:id="@+id/txt_product_eng_name"
                android:layout_margin="8dp"
                android:gravity="right"/>

        </LinearLayout>

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

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

        <Button
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/title_btn_compare"
            android:drawableLeft="@drawable/ic_compare"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:drawablePadding="10dp"
            android:drawableTint="@color/textSecondary"
            android:textColor="@color/textPrimary"
            android:textSize="18sp"
            android:id="@+id/btn_compare"
            android:background="@drawable/btn_white_background"
            android:layout_margin="8dp"/>

        <Button
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/title_btn_product_comments"
            android:drawableLeft="@drawable/ic_user_comments"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:drawablePadding="10dp"
            android:drawableTint="@color/textSecondary"
            android:textColor="@color/textPrimary"
            android:textSize="18sp"
            android:id="@+id/btn_comments"
            android:background="@drawable/btn_white_background"
            android:layout_margin="8dp"/>

    </LinearLayout>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lay_product_property"
        app:cardElevation="1dp"
        app:cardCornerRadius="0dp"
        app:cardUseCompatPadding="true"
        app:cardPreventCornerOverlap="false"
        android:layout_marginBottom="2dp"
        app:contentPadding="2dp">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/colorAccent"
                android:id="@+id/txt_product_property"
                android:text="@string/title_card_properties"
                android:layout_margin="8dp"
                android:gravity="right"/>

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clipToPadding="false"
                    android:id="@+id/rec_property"/>

        </LinearLayout>

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

</LinearLayout>

</android.support.v4.widget.NestedScrollView>`

when i run the app recyclerView push top layers up outside the screen. How fix it?

ShamylZakariya commented 7 years ago

For StickyHeadersLayoutManager to work, your recyclerview needs to have constant height, or match_parent or have a height of 0 and a layout_weight of some non-zero value. StickyHeadersLayoutManager expects to scroll, and if you use wrap_content, you will by definition not get scrolling behavior.

If you want sectioning layout but want wrap_content behavior, you can use SectioningAdapter, but use a vanilla LinearLayoutManager.