boolean areItemsTheSame( int oldItemPosition, int newItemPosition) {} @Override public boolean areContentsTheSame( int oldItemPosition, int newItemPosition) {} }
= 0; public static final int CARD = 1; public static final int FULL_BLEED_CARD = 2; public static final int SQUARE_CARD = 3; public static final int SMALL_CARD = 4; } naïve way
= 0; public static final int CARD = 1; public static final int FULL_BLEED_CARD = 2; public static final int SQUARE_CARD = 3; public static final int SMALL_CARD = 4; } better way
public PhotoModel(Photo photo) { this.photo = photo; } @LayoutRes public int getDefaultLayout() { return R.layout.view_model_photo; } @Override public void bind(PhotoView photoView) { photoView.setUrl(photo.getUrl()); } } Epoxy need a custom view or view holder for each item
all your desired column splits • I want single, double, triple & quad columns LCM(1, 2, 3, 4) = 12 • No performance hit from having a large num of columns. (Large num of items might be)
public SongItem(Song song) { this.song = song; } @Override public void bind(ViewHolder viewHolder, int position) {…} @Override public int getLayout() { return R.layout.song; } @Override public int getSpanSize(int spanCount, int position) { // individual item’s span size } } Item
public SongItem(Song song) { this.song = song; } @Override public void bind(ViewHolder viewHolder, int position) {…} @Override public int getLayout() { return R.layout.song; } @Override public int getSpanSize(int spanCount, int position) { // individual item’s span size } } Item
…? @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(view); GridLayoutManager.LayoutParams layoutParams = view.getLayoutParams(); GridLayoutManager gridLayoutManager = parent.getLayoutManager(); int spanSize = layoutParams.getSpanSize(); int totalSpanSize = gridLayoutManager.getSpanCount(); if (spanSize + layoutParams.getSpanIndex() == totalSpanSize) { // Item reaches to right edge of list outRect.right = padding; } if (layoutParams.getSpanIndex() == 0) { // Item's left edge is on left edge of list outRect.left = padding; } }
…? @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(view); GridLayoutManager.LayoutParams layoutParams = view.getLayoutParams(); GridLayoutManager gridLayoutManager = parent.getLayoutManager(); int spanSize = layoutParams.getSpanSize(); int totalSpanSize = gridLayoutManager.getSpanCount(); if (spanSize + layoutParams.getSpanIndex() == totalSpanSize) { // Item reaches to right edge of list outRect.right = padding; } if (layoutParams.getSpanIndex() == 0) { // Item's left edge is on left edge of list outRect.left = padding; } }
…? @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(view); GridLayoutManager.LayoutParams layoutParams = view.getLayoutParams(); GridLayoutManager gridLayoutManager = parent.getLayoutManager(); int spanSize = layoutParams.getSpanSize(); int totalSpanSize = gridLayoutManager.getSpanCount(); if (spanSize + layoutParams.getSpanIndex() == totalSpanSize) { // Item reaches to right edge of list outRect.right = padding; } if (layoutParams.getSpanIndex() == 0) { // Item's left edge is on left edge of list outRect.left = padding; } }
…? @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(view); GridLayoutManager.LayoutParams layoutParams = view.getLayoutParams(); GridLayoutManager gridLayoutManager = parent.getLayoutManager(); int spanSize = layoutParams.getSpanSize(); int totalSpanSize = gridLayoutManager.getSpanCount(); if (spanSize + layoutParams.getSpanIndex() == totalSpanSize) { // Item reaches to right edge of list outRect.right = padding; } if (layoutParams.getSpanIndex() == 0) { // Item's left edge is on left edge of list outRect.left = padding; } }
…? @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(view); GridLayoutManager.LayoutParams layoutParams = view.getLayoutParams(); GridLayoutManager gridLayoutManager = parent.getLayoutManager(); int spanSize = layoutParams.getSpanSize(); int totalSpanSize = gridLayoutManager.getSpanCount(); if (spanSize + layoutParams.getSpanIndex() == totalSpanSize) { // Item reaches to right edge of list outRect.right = padding; } if (layoutParams.getSpanIndex() == 0) { // Item's left edge is on left edge of list outRect.left = padding; } }
for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); int position = parent.getChildAdapterPosition(child); } } use layout position
for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); int position = parent.getChildAdapterPosition(child); } } use layout position can be NO_POSITION during animation
for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); int position = parent.getChildLayoutPosition(child); } } use layout position