【发布时间】:2015-08-25 07:21:31
【问题描述】:
我正在使用 RecyclerView 并且我正在尝试使 RecyclerView 的宽度项 match_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);
ViewHolder
View view= LayoutInflater.from(parent.getContext())
.inflate(R.layout.custom_layout, parent, false);
ViewOffersHolder viewHolder=new ViewOffersHolder(view);
return viewHolder;
【问题讨论】:
-
@Rami 感谢您的评论,我已经尝试了两种建议的解决方案,但仍然相同。而且我不认为 CardView 的问题,因为我将其更改为
FrameLayout并且仍然相同。 -
我找到的最佳解决方案在这里:stackoverflow.com/a/62139337/13588475
标签: android xml android-recyclerview