Cardview - 卡周围的白色边框

The*_*hod 31 android android-cardview

我正在使用cardview作为我正在编写的自定义视图的根.我使用的是v7支持库.我的XML看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginRight="6dp"
        card_view:cardElevation="0dp">

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

        <!-- some other views -->
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

我的问题是我的卡片视图周围有一个白色边框.它看起来像是指示高度,因为它在右侧较厚.我试过调整,cardElevationMaxCardElevation在我的XML中这样: card_view:cardElevation="0dp"

并在我的自定义视图中的代码中扩展CardView并使用此布局:

setCardElevation(0);
setMaxCardElevation(0);
Run Code Online (Sandbox Code Playgroud)

但白色边界仍然存在.我不知道如何摆脱它.如果有人对此为何发生任何意见或建议如何删除白色边框,我们将不胜感激.非常感谢.

小智 84

我知道这有点晚了,但对于有类似问题的人:

我遇到了同样的问题:在棒棒糖前设备上显示了白色边框.

我解决了它的设置cardPreventCornerOverlapfalse你的XML.

像这样:

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginRight="6dp"
    card_view:cardPreventCornerOverlap="false">

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

        <!-- some other views -->
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

  • 对我来说,它是`app:cardPreventCornerOverlap ="false"`而不是`card_view:cardPreventCornerOverlap ="false"`.我改变了这个并且它起作用了. (4认同)
  • 这是应用程序:cardUseCompatPadding ="true",因为我从xmlns扩展:app ="http://schemas.android.com/apk/res-auto".小心的家伙们!时间消费者!XD (2认同)
  • 谢谢!有用.但有一个问题.添加此标记后,它会忽略角半径.我怎么解决这个问题? (2认同)
  • cardPreventCornerOverlap ="false"和contentPadding ="0dp" (2认同)