我想将具有LayoutManager作为LinearLayoutManager的水平方向放置在recyclerView中的中心位置。
这是我的代码示例:
LinearLayoutManager lm = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
RecyclerView.ItemDecoration decoration = new WidgetMarginItemDecoration(getContext());
recyclerView.setNestedScrollingEnabled(true);
recyclerView.addItemDecoration(decoration);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(m.get(0).getGroupName() == null || m.get(0).getGroupName().isEmpty() ? ngm : lm);
recyclerView的布局:
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
/>
图像显示了我想要的:红色分隔线上方是我现在想要的东西,红色分隔线下方是我想要实现的
以及许多物品的布局之一:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="32dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>