1.ListView的itemView设置margin是无效的,因为listView中Item的LayoutParam是直接继承自ViewPager中的LayoutParam, 没有margin属性。
2.RecyclerView的itemView布局如果是纯linearlayout,宽度设置match_parent后并不会充满父控件宽度,示例如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/divider_bottom" > <TextView android:id="@+id/last_month" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:paddingStart="@dimen/space_large" android:text="上个月" /> <TextView android:id="@+id/month" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:paddingBottom="@dimen/space_mid" android:paddingTop="@dimen/space_mid" android:text="2016年9月" android:textColor="@color/title_blue" /> <TextView android:id="@+id/next_month" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:paddingEnd="@dimen/space_large" android:text="下个月" /> </LinearLayout>
实际运行效果:
从图可以看出虽然线性布局设置了match_parent但是实际宽度却并没有达到match_parent的效果,如果线性布局多层嵌套线性布局仍然是会出现同样的问题,但如果不是纯线性布局比如线性布局中的子布局有相对布局那么就不会存在这个问题了