我想把recycler中的每个元素都重叠到右边,因为我正在实现itemdecorator类,它确实这样做了,但它也从右边剪切了最后一个视图,对此的任何帮助都将不胜感激。

public class ItemDecorator extends RecyclerView.ItemDecoration {
private final int mSpace;

public ItemDecorator(int space) {
    this.mSpace = space;
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    //outRect.left = mSpace;
    outRect.right = mSpace;
    //outRect.bottom = mSpace;
    //outRect.top = mSpace;
}
}

eventDetailBinding.participantList.setHasFixedSize(true);
               RecyclerView.LayoutManager layoutManagerForParticipants =
                       new LinearLayoutManager(EventDetailActivity.this, LinearLayoutManager.HORIZONTAL, false);
               eventDetailBinding.participantList.setLayoutManager(layoutManagerForParticipants);
               ItemDecorator itemDecorator = new ItemDecorator(-30);
               eventDetailBinding.participantList.addItemDecoration(itemDecorator);
               eventDetailBinding.participantList.setAdapter(new ParticipantViewAdapter(EventDetailActivity.this, imageList));

图像=https://image.ibb.co/hivnLF/Untitled.png

最佳答案

我终于找到了我的问题的解决方案,它是clipToPadding="false"和设置paddingRight="8dp"在我的回收视图。

<android.support.v7.widget.RecyclerView
                            android:id="@+id/participant_list"
                            android:paddingLeft="4dp"
                            android:paddingRight="8dp"
                            android:clipToPadding="false"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"/>

10-07 22:46