这样的问题是需要在RecyclerView中显示元素,可能元素的数量是1到9,如何让这些元素从RecyclerView的中心显示出来
RecyclerView创建代码和适配器创建:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cards_users"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_gravity="center"
app:layout_constraintTop_toBottomOf="@+id/game_map"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottom_menu">
</androidx.recyclerview.widget.RecyclerView>
gameUserClass=deserializeGameCardsList(server_answer);
cardsUser=findViewById(R.id.cards_users);
RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(GameActivity.this, LinearLayoutManager.HORIZONTAL, false);
cardsUser.setLayoutManager(layoutManager1);
cardsPlayerAdapter= new CardsPlayerAdapter(gameUserClass.getFirstPlayer());
cardsUser.setAdapter(cardsPlayerAdapter);