CardView layout_width =“ match_parent”与父RecyclerView宽度不匹配
我有一个片段,其中包含一个带有layout_width =“ match_parent”的RecyclerView: <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity$PlaceholderFragment" /> RecyclerView中的项目也是CardView,它也具有layout_width =“ match_parent”: <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="20dp" card_view:cardCornerRadius="4dp"> <TextView android:layout_gravity="center" android:id="@+id/info_text" android:layout_width="match_parent" android:gravity="center" android:layout_height="match_parent" android:textAppearance="?android:textAppearanceLarge"/> </android.support.v7.widget.CardView> 我将项目视图充气如下: public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { CardView v = (CardView) LayoutInflater.from(parent.getContext()) .inflate(R.layout.card_listitem, null, …