lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

SpacingItemDecoration Uneven With notifyItemInserted #161

Open eygraber opened 9 years ago

eygraber commented 9 years ago

I have a TwoWayView that uses a GridLayoutManager:

<org.lucasr.twowayview.widget.TwoWayView
        android:id="@+id/favorite_contacts_grid"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".90"
        android:layout_marginTop="30dp"
        android:paddingLeft="15dp"
        android:paddingStart="15dp"
        android:paddingRight="15dp"
        android:paddingEnd="15dp"
        app:twowayview_layoutManager="GridLayoutManager"
        app:twowayview_numColumns="4"
        app:twowayview_numRows="4"
        android:gravity="center"/>

My adapter has a method to add items:

public void addItem(Item item) {
    int sortPosition = item.getSortPosition();
    if(sortPosition < items.size()) {
        items.add(sortPosition, item);
        notifyItemInserted(sortPosition);
    }
    else {
        items.add(item);
        notifyItemInserted(items.size() - 1);
    }
}

I call twv.addItemDecoration(new SpacingItemDecoration(30, 30)), and some of the grid items are out of position (either raised or lowered). If I replace notifyItemInserted with notifyDataSetChanged everything works fine.

neoRiley commented 9 years ago

notifyDataSetChanged also worked for me - thank you for posting that

ppamorim commented 9 years ago

+1