🙂 Hello,村长
布局效果对比
前
后
解决
不居中的原因,我的 item 布局根容器使用的是 ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
布局根容器使用 LinearLayout
即可,必须同时指定 android:layout_width="match_parent" 和 android:gravity="center"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
我的上述布局,根布局容器 LinearLayout 只有一个子控件,就是 ConstraintLayout,如有差异,请调整自己的子控件。