首页 > 解决方案 > CardView 不屏蔽父级内部

问题描述

我想放CardView里面Rounded LinearLayout。但是我的布局仍然是方形的,但是如果我放置另一个视图,它是圆形的。

<LinearLayout
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@drawable/rounded">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        app:cardPreventCornerOverlap="false" />
</LinearLayout

这是我的圆形布局

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white"/>
    <stroke
        android:width="3dp"
        android:color="@color/white" />
    <corners android:radius="8dp"/>
</shape>

我尝试使用app:cardPreventCornerOverlap="false"但仍然无法正常工作。我的卡如何变成圆形,因为它在圆形的父级内?

我尝试了另一种方法。
我使用 CardView 和实现更改父级app:cardCornerRadius

<android.support.v7.widget.CardView
    android:layout_width="100dp"
    android:layout_height="100dp"
    app:cardCornerRadius="8dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        app:cardPreventCornerOverlap="false" />
</LinearLayout

但还是一样,CardView孩子覆盖CardView父母

标签: androidandroid-cardview

解决方案


给 相等的半径CardView

<LinearLayout
    ...>

    <android.support.v7.widget.CardView
        app:cardCornerRadius="8dp"
        ... />
</LinearLayout

推荐阅读