CardView:让子项重叠

Bla*_*cos 4 xml android android-cardview

我的RecyclerView有问题.我想设计一些看起来像这样的CardView:

Twitter卡

因此,我需要左上角的ImageView与CardView重叠.我已经知道负边距的用法,但我的问题主要是

即使clipToPadding设置为false,Cardview中的重叠也会被裁剪

有没有人有这个问题的解决方案?

Fer*_*med 7

只是设置ImageView(Twitter图标)elevationCardView高程更高.

设置android:elevation="10dp"ImageView并设置 card_view:cardElevation="2dp"CardView.

这是一个例子:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true">

        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="20dp"
            card_view:cardElevation="2dp"
            card_view:cardCornerRadius="4dp"
            card_view:cardUseCompatPadding="false"
            card_view:cardPreventCornerOverlap="false">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/sample_1" />

                <TextView
                    android:id="@+id/title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/image"
                    android:padding="8dp"
                    android:background="#CCFFFFFF"
                    android:text="This is simple title"
                    android:textColor="#000000" />
            </RelativeLayout>
        </android.support.v7.widget.CardView>

        <ImageView
            android:id="@+id/icon_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dp"
            android:elevation="10dp"
            android:src="@mipmap/ic_launcher"/>
    </RelativeLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

OUTPUT:

在此输入图像描述

希望这会有所帮助〜