Android 水平滚动的recycleview/cardview宽度错误

Android 水平滚动的recycleview/cardview宽度错误,android,horizontal-scrolling,Android,Horizontal Scrolling,我在水平滚动的RecycleView中设置CardView的正确宽度尺寸时遇到问题 这是卡片xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_wid

我在水平滚动的
RecycleView
中设置
CardView
的正确宽度尺寸时遇到问题

这是卡片xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">

<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
    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="150dp"
    card_view:cardCornerRadius="4dp">

<TextView
    android:id="@+id/info_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
我的活动中的直线布局经理:

mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recycleView.setLayoutManager(mLayoutManager);
最后,这是我的适配器:

...
public static class ViewHolder extends RecyclerView.ViewHolder {
    CardView cv;
    TextView nameTV;

    ViewHolder(View itemView) {
        super(itemView);
        cv = (CardView)itemView.findViewById(R.id.card_view);
        nameTV = (TextView)itemView.findViewById(R.id.info_text);
    }
}


public MyCardAdapter(List<Dog> myDataset) {
    mDataset = myDataset;
}


@Override
public MyCardAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_card, parent, false);
    ViewHolder vh = new ViewHolder(v);

    return vh;
}
。。。
公共静态类ViewHolder扩展了RecyclerView.ViewHolder{
卡德维尤简历;
文本视图名称电视;
ViewHolder(视图项视图){
超级(项目视图);
cv=(CardView)itemView.findViewById(R.id.card\u视图);
nameTV=(TextView)itemView.findViewById(R.id.info\u text);
}
}
公共MyCardAdapter(列出myDataset){
mDataset=myDataset;
}
@凌驾
public MyCardAdapter.ViewHolder onCreateViewHolder(视图组父级,int-viewType){
视图v=LayoutInflater.from(parent.getContext()).flate(R.layout.my_card,parent,false);
视窗支架vh=新视窗支架(v);
返回vh;
}
这就是结果:

但我希望循环视图占据所有水平空间;大概是这样的:


只需将onCreateViewHolder更改为:

@Override
public MyCardAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_card, parent, false);
v.setMinimumWidth(parent.getMeasuredWidth());
ViewHolder vh = new ViewHolder(v);

return vh;
}
@Override
public MyCardAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_card, parent, false);
v.setMinimumWidth(parent.getMeasuredWidth());
ViewHolder vh = new ViewHolder(v);

return vh;
}