ShamylZakariya / StickyHeaders

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

Margin properties on Items in StickyHeaderLayoutManager #3

Open PACordonnier opened 8 years ago

PACordonnier commented 8 years ago

Hey, I'm using a RecyclerView which contains CardViews and want to have StickyHeaders.

When using a LinearLayout in my RecyclerView, I can't get a Sticky Header only a header separating the cards (it's already a huge improvement actually). I'm guessing that this is correct behaviour with this layout.

But when using the provided layout it seems like the margin properties on my card have no effect and takes the whole screen. linear sticky

PACordonnier commented 8 years ago

Okay so I used a workaround in order to make it work properly.

I encapsulate my CardView inside a simple LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    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_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginBottom="@dimen/vertical_margin_half"
        android:layout_marginLeft="@dimen/vertical_margin"
        android:layout_marginRight="@dimen/vertical_margin"
        android:layout_marginTop="@dimen/vertical_margin_half"
        card_view:cardCornerRadius="2dp">

I'm not closing the issue but I hope this helps ;) Thanks for the library !

ShamylZakariya commented 8 years ago

Interesting. I have to assume this is something to do with CardView -- StickyHeaderLayoutManager simply asks for how tall the item wants to be when laid out, it doesn't do anything special. Glad you were able to find a workaround, but let's leave this open so I can think about this.

robotsquidward commented 6 years ago

Seconding this, using CardView as a header locked all the views into the same height, even after changing visibility to GONE or doing wrap_content on the height.

I wrapped my CardView in a FrameLayout and it's working like a charm.

benyAlves commented 4 years ago

Hi I am facing the same issue, is there an official solution? This Issue is opened since 2016