我正在开发将CardView与RecyclerView结合使用的应用程序。
我想减少两个卡片项目之间的空间。要指定卡片视图的宽度。(不想将宽度设置为MATCH_PARENT)
下面是我的代码-
我已经尝试过card_view:cardMaxElevation="1dp"
,card_view:cardElevation="1dp"
和card_view:contentPadding="-8dp"
,但这对我不起作用。
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_marginTop="15dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"/>
这是我的卡片视图-
<android.support.v7.widget.CardView
android:id="@+id/companyNameCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardBackgroundColor="@color/logo_yellow_light"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="3dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="8dp">
<RelativeLayout
android:id="@+id/mainCardRelative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/full_transparent_color">
<RelativeLayout
android:id="@+id/thumbnailRelative"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:background="@color/full_transparent_color">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:contentDescription="@string/app_name"
android:focusable="true"
android:src="@drawable/ic_job" />
</RelativeLayout>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/thumbnailRelative"
android:background="@color/full_transparent_color"
android:gravity="start"
android:padding="5dp"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="13sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
这就是我要得到的
答案 0 :(得分:0)
将两个项目都包裹在“ LinearLayout”中,以使它们彼此相邻。
<android.support.v7.widget.CardView
android:id="@+id/companyNameCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardBackgroundColor="@color/logo_yellow_light"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="3dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="8dp">
<LinearLayout
android:id="@+id/mainCardRelative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/full_transparent_color">
<RelativeLayout
android:id="@+id/thumbnailRelative"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:background="@color/full_transparent_color">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:contentDescription="@string/app_name"
android:focusable="true"
android:src="@drawable/ic_job" />
</RelativeLayout>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/thumbnailRelative"
android:background="@color/full_transparent_color"
android:gravity="start"
android:padding="5dp"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="13sp" />
</LinearLayout>
</android.support.v7.widget.CardView>