我试图使用RecyclerView与CardView作为列表的单个项目.
我想实现水平列表,LayoutManager这很容易.
所以我开始实施它.似乎一切正常,但不像我预期的那样是使用CardView作为列表项的结果.

看起来不错,但我没有设置任何衬垫,分隔线和圆角.
这是我的XML for card view项目.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:id="@+id/image_view"
android:src="@drawable/androidsss"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
/>
<TextView
android:id="@+id/info_text"
android:layout_below="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@android:color/black"
android:textSize="14sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
在布局的底部还有类似小分隔线的东西.
我没有指明任何.
这是我为RecyclerView设置的代码
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecyclerView.setLayoutManager(mLayoutManager);
// mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(this));
mAdapter = new CardViewDataAdapter(myDataset);
mRecyclerView.setAdapter(mAdapter);
Run Code Online (Sandbox Code Playgroud)
有趣的事情,简单的项目,而不是卡片视图,一切都按预期工作.这是一个例子.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="150dp"
android:layout_height="100dp" …Run Code Online (Sandbox Code Playgroud) android android-layout android-listview android-cardview android-recyclerview