首先,对不起,如果这是一个愚蠢的问题.我不是很懒.所以,问题是,我试图在Android应用程序中实现CardView/RecyclerView.我做到了,但问题是卡片彼此隔开,我不知道如何解决它.我探索了代码,但一切似乎都很好.
代码 :
RecyclerView
<android.support.v7.widget.RecyclerView
android:id="@+id/collapsing_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:padding="@dimen/activity_horizontal_margin">
</android.support.v7.widget.RecyclerView>
Run Code Online (Sandbox Code Playgroud)
CardView项目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
card_view:cardBackgroundColor="@color/colorAccent"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp">
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Text"
android:id="@+id/cardview.name" />
</android.support.v7.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
适配器:
public class MyRecyclerViewAdapter extends RecyclerView
.Adapter<MyRecyclerViewAdapter
.DataObjectHolder> {
private static String LOG_TAG = "MyRecyclerViewAdapter";
private ArrayList<CardViewItem> mDataset;
private static MyClickListener myClickListener;
public static class DataObjectHolder extends RecyclerView.ViewHolder
implements View
.OnClickListener {
TextView label;
public DataObjectHolder(View itemView) {
super(itemView);
label = …Run Code Online (Sandbox Code Playgroud)