Java 自定义CardView边框显示两次

Java 自定义CardView边框显示两次,java,android,android-cardview,Java,Android,Android Cardview,我定制了一些CardView,如下所示: public class CustomCard extends CardView { public CustomCard(Context context) { this(context, null); } public CustomCard(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0);

我定制了一些CardView,如下所示:

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边框,如下所示(很明显,在边框处有两层立面):

有人有主意吗?谢谢

编辑:

自定义CardView的一个xml:

<?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>

看起来您正在自定义卡视图中膨胀
卡视图
,这导致了此问题


要解决此问题,请将您的
layout/custom\u card.xml
更改为将
RelativeLayout
作为父级,而不是
cardwiew

您是否可以发布card\u custom和其他任何版面的xml?我假设如果在某个布局中插入其他内容(如空视图),则不会得到边框。是的,这是真的。谢谢。那么,如何让
cardwiew
成为
CustomControl
呢?因为它现在是
RelativeLayout
而不是
CardView
,所以我们不能使用像
cardCornerRadius
之类的东西?(我也面临同样的问题)