MaterialCardView的不同角半径值 [英] Different corner radius values for a MaterialCardView

本文介绍了MaterialCardView的不同角半径值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于MaterialCardView的每个角半径,是否可以具有不同的值?如果是这样怎么办?

Is is possible to have different values for each corner radius of a MaterialCardView? And if so how?

我尝试了类似下面的代码,但似乎没有任何作用

I tried something like the code below but it doesn't seem to have any effect

    float radius = getContext().getResources().getDimension(R.dimen.default_corner_radius);
    ShapePathModel leftShapePathModel = new ShapePathModel();
    leftShapePathModel.setTopLeftCorner(new RoundedCornerTreatment(radius));
    leftShapePathModel.setTopRightCorner(new RoundedCornerTreatment(radius));
    MaterialShapeDrawable bg = new MaterialShapeDrawable(leftShapePathModel);
    container.setBackground(bg);

容器在哪里

@BindView(R.id.container) MaterialCardView container;

推荐答案

我最初的解决方案是正确的,但缺少一行:

My initial solution was correct but it was missing one line:

float radius = getContext().getResources().getDimension(R.dimen.default_corner_radius);
ShapePathModel leftShapePathModel = new ShapePathModel();
leftShapePathModel.setTopLeftCorner(new RoundedCornerTreatment(radius));
leftShapePathModel.setTopRightCorner(new RoundedCornerTreatment(radius));
MaterialShapeDrawable bg = new MaterialShapeDrawable(leftShapePathModel);
container.setBackground(bg);

如果添加

container.invalidate()

正如卡梅伦在上文中所建议的,

似乎有效.

as suggested by Cameron above it seems to work.

这篇关于MaterialCardView的不同角半径值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆