自定义 CardView 边框显示两次

Custom CardView border showed twice

我定制了一些这样的卡片视图:

public class CustomCard extends CardView {

    public CustomCard(Context context) {
        this(context, null);
    }

    public CustomCard(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public CustomCard(Context context, AttributeSet attributeSet, int defStyle) {
        super(context, attributeSet, defStyle);

        //R.layout.card_custom is the custom xml file 
        inflate(context, R.layout.card_custom, this);
    }
}

然后我构建并将它们添加到 ViewGroup 中,如下所示:

CustomCard card = new CustomCard(this);
someLayout.addView(card);

问题是我会在 UI 中看到两层 CardView 边框,如下所示(很明显边框处有两层高程):

有人有想法吗?谢谢

编辑:

一个 xml 自定义 CardView:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="14dp"
        android:layout_marginBottom="14dp">

        <!--- Some Details --->

    </RelativeLayout>

</android.support.v7.widget.CardView>

我上面提到的一些布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_gray">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!--- Details --->

    </LinearLayout>

</ScrollView>

您似乎在自定义卡片视图中膨胀 CardView,这导致了此问题。

要解决此问题,请将 layout/custom_card.xml 更改为将 RelativeLayout 作为父级而不是 CardView