Mặc dù câu hỏi này là hơn một năm cũ, tôi nghĩ rằng tôi muốn chia sẻ những gì tôi đã làm, ai đó có thể thích nó, hoặc chỉ không muốn gõ và có thể sao chép/dán này: D.
Giải pháp của tôi là thêm một số lề dưới vào mục cuối cùng.
Trước tiên tôi xác định rằng nó là mục cuối cùng:
@Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
....
Your other code
....
// Check if it is the last item and the list is not empty.
if(position == mItems.size()-1) {
// If so, add some margin to the element
holder.setBottomMargin(R.dimen.last_item_offset); // some dimension (or set a fixed amount of pixels
}
}
Sau đó, tôi có một phương pháp trong viewholder để thiết lập lề dưới.
class ItemViewHolder extends RecyclerView.ViewHolder {
private View mRootView;
private Context mContext;
public ItemViewHolder(View itemView) {
super(itemView);
mRootView = itemView;
mContext = itemView.getContext();
// do more stuff like binding views, etc
}
public void setBottomMargin(@DimenRes int margin){
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) mRootView.getLayoutParams();
layoutParams.bottomMargin = (int)getContext().getResources().getDimension(margin);
mRootView.setLayoutParams(layoutParams);
}
}
Và cho đầy đủ các ví dụ này, kích thước
<resources>
<dimen name="spot_list_footer_position_offset">-56dp</dimen>
</resources>
Tôi hy vọng điều này là những gì bạn đang tìm kiếm.
Điều này. Giải pháp đơn giản nhất. –