首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >带有圆角的Android CardView显示灰色角

带有圆角的Android CardView显示灰色角
EN

Stack Overflow用户
提问于 2018-01-15 02:50:10
回答 5查看 27.1K关注 0票数 37

我正在膨胀一个自定义布局,在布局中使用CardView。圆角显示如预期,但我也得到灰色背景后面的角。

代码很简单,使用的是具有角半径和背景颜色的CardView。我试过设置透明的背景,但不起作用。然而,如果我设置另一个不透明的颜色,它将显示在角。

密码是附加的。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
    android:background="@android:color/transparent">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@android:color/white"
        app:cardCornerRadius="6dp"
        app:cardElevation="5dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent">

            <TextView
                android:id="@+id/tvProgress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/ivIcon"
                android:layout_toStartOf="@+id/ivIcon"
                android:background="@android:color/transparent"
                android:padding="@dimen/elementPaddingSmall"
                android:text="Initial Discussion"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@android:color/black" />

            <ImageView
                android:id="@+id/ivIcon"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:background="@color/lightBrown"
                android:scaleType="centerInside"
                android:src="@drawable/ic_checkmark_circle" />
        </RelativeLayout>


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

结果:

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2018-01-15 02:59:28

这是因为阴影,你需要给予空间的卡纸,以显示完整的阴影。将android:layout_margin="5dp"添加到CardView中,您将看到“灰色”颜色是裁剪阴影。

解决方案正在将app:cardUseCompatPadding="true"添加到CardView中,它将给出所需的间距。

票数 66
EN

Stack Overflow用户

发布于 2018-01-15 03:10:47

试试这个..。

只需将0设置为app:cardElevation

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
.....
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="6dp"
    app:cardElevation="0dp">
.....

您可以调用cardView.setCardElevation(0)以编程方式禁用阴影。

票数 11
EN

Stack Overflow用户

发布于 2018-01-15 03:21:15

删除正在包装RelativeLayout的父CardView,您就可以继续了。就像这样:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?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="wrap_content"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="6dp"
    app:cardElevation="5dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

        <TextView
            android:id="@+id/tvProgress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/ivIcon"
            android:layout_toStartOf="@+id/ivIcon"
            android:background="@android:color/transparent"
            android:padding="@dimen/elementPaddingSmall"
            android:text="Initial Discussion"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"/>

        <ImageView
            android:id="@+id/ivIcon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:background="@color/lightBrown"
            android:scaleType="centerInside"
            android:src="@drawable/ic_checkmark_circle"/>
    </RelativeLayout>


</android.support.v7.widget.CardView>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48261460

复制
相关文章
Android:最简单的图片圆角制作(卡片布局)
在APP中,图片往往设计成圆角,非常美观。 但查阅资料发现实际操作比较复杂,大致有两种方法。 第一种很复杂:在JAVA代码中修改图片的shape,代码难写且冗长。 第二种很滑稽:采用一张透明的View覆盖图片的四角,有些自欺欺人,如果设备不兼容,小动作直接暴露无遗。
zstar
2022/06/14
1K0
Android:最简单的图片圆角制作(卡片布局)
Android之CardView[通俗易懂]
CardView是View的子类,View一般使用Background设置背景色,为什么还要单独提取出一个属性让我们来设置背景色呢?
全栈程序员站长
2022/11/07
6.5K0
Android之CardView[通俗易懂]
Android项目实战(三十六):给背景加上阴影效果
圆角背景大家应该经常用: 一个drawable资源文件  里面控制corner圆角 和solid填充色  <shape xmlns:android="http://schemas.android.co
听着music睡
2018/05/18
1.6K0
CardView
在Google I/O 2014上,Google公布了Android L Preview版本,此版本的UI有了非常大的改变,很炫很给力!同时,Google也给出了两个可以向下兼容的控件放到了V7包中,
xiangzhihong
2018/02/01
2.1K1
CardView
CardView的那点事儿
类继承关系: java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.widget.FrameLayout ↳ android.support.v7.widget.CardView
小小工匠
2021/08/16
1K0
学会使用CardView,简单实现卡片式布局效果
还记得我们一共学过了多少UI控件了吗?都掌握的怎么样啊 安卓中一些常用控件学习得差不多了,今天再来学习一个新的控件CardView,在实际开发中也有非常高的地位。 一、CardView简介 CardView是Android 5.0系统引入的控件,相当于FragmentLayout布局控件然后添加圆角及阴影的效果。 CardView继承自Framelayout,所以FrameLayout所有属性CardView均可以直接拿来用,不过CardView还有自己独有的属性,常用属性
分享达人秀
2018/02/05
3.4K0
学会使用CardView,简单实现卡片式布局效果
CSS3圆角详解
CSS3是样式表(style sheet)语言的最新版本,它的一大优点就是支持圆角。
ruanyf
2018/09/21
9660
CSS3圆角详解
Android 中的那些圆角
引用关键字 implement、api和compile区别 图片圆角 加载处理原图圆角 Glide和Picasso Glide 下载地址:https://github.com/bumptech/glide 使用文档:https://muyangmin.github.io/glide-docs-cn/ 使用扩展Glide Transformations 扩展地址:https://github.com/wasabeef/glide-transformations repositories { jcent
码客说
2019/10/22
1.2K0
Material Design 实战 之第四弹 —— 卡片布局
首先这里准备用CardView来填充主题内容, CardView是用于实现卡片式布局效果的重要控件,由appcompat-v7库提供。 实际上,CardView也是一个FrameLayout,只是额外提供了圆角和阴影等效果,看上去会有立体的感觉。
凌川江雪
2018/10/09
2.1K0
Material Design 实战 之第四弹 —— 卡片布局
2-VVI-材料设计之CardView
零、前言 [1].CardView extends FrameLayout [2].一个带圆角和阴影的FrameLayout,FrameLayout怎么用,它就怎么用 [3].依赖impleme
张风捷特烈
2018/09/29
1.2K0
2-VVI-材料设计之CardView
还在用shape、selector,试试自定义圆角组件吧
在进行Android应用开发过程中,设计师经常会给应用中涉及的卡片和按钮来个圆角。对于卡片,我们可以直接使用CardView等,对于圆角按钮通常会shape、selector等xml的方式进行配置。
xiangzhihong
2021/12/30
3900
还在用shape、selector,试试自定义圆角组件吧
UIProgressView 当前进度显示圆角
也就是把 UIProgressView的trackTintColor设置为透明。假如进度条没有填满是效果是这样的
赵哥窟
2018/09/13
2.8K0
UIProgressView 当前进度显示圆角
Android 实现圆角布局
和尚我最近在处理图片的圆角,不止是四个角全是圆角,还包括单左侧/单右侧/对角线方向的圆角。因为自己太菜只能寻求网上的大神,发现一个自定义圆角布局,这样可以变相的解决我的需求,还可以实现更多的圆角效果,不仅是图片,还包括其他布局。 和尚我作为伸手党,非常感谢大神的分享,参考原文 RoundAngleFrameLayout。 这个布局实现方式很简单,大神只提供了默认的四个圆角,这里我添加了一些方法可以动态的设置圆角的位置与弧度,并说明一下和尚我遇到的小问题。和尚我根据大神的总结自定义了一个 MyRoundLayout GitHub 布局样式。
阿策小和尚
2019/08/12
2.2K0
Android 实现圆角布局
点击加载更多

相似问题

CardView圆角未在Android预览中显示

20

在CardView中没有圆角的AlertDialog角

12

使用子视图覆盖CardView圆角:android

11

删除CardView的圆角

30

创建带有圆角的列表视图显示部分角

23
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文