我正在使用RecyclerView,并尝试使RecyclerView的宽度匹配_parent,因为我正在使用
LinearLayoutManager.HORIZONTAL
<android.support.v7.widget.RecyclerView
android:id="@+id/listOffersHits"
android:layout_width="match_parent"
android:layout_height="match_parent" />
自定义布局文件 custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<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_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:layout_margin="2dp"
card_view:cardCornerRadius="2dp">
<ImageView
android:id="@+id/offerImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/item_selector"
android:scaleType="fitXY"
android:src="@drawable/offer"
/>
</android.support.v7.widget.CardView>
布局管理器
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL, false);
listOffersHits.setLayoutManager(linearLayoutManager);
视图持有者
View view= LayoutInflater.from(parent.getContext())
.inflate(R.layout.custom_layout, parent, false);
ViewOffersHolder viewHolder=new ViewOffersHolder(view);
return viewHolder;