gpt4 book ai didi

android - MaterialCardView 的不同角半径值

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:08 25 4
gpt4 key购买 nike

是否可以为 MaterialCardView 的每个角半径设置不同的值?如果是这样怎么办?

我试过类似下面的代码,但似乎没有任何效果

    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;

最佳答案

您可以使用自定义样式shapeAppearanceOverlay 属性。

  <style name="MyCardView" parent="@style/Widget.MaterialComponents.CardView">
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MaterialCardView.Cut</item>
</style>


<style name="ShapeAppearanceOverlay.MaterialCardView.Cut" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">8dp</item>
<item name="cornerSizeTopLeft">8dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
</style>

或者您可以应用自定义 ShapeAppearanceModel使用类似的东西到卡片的一角:

float radius = getResources().getDimension(R.dimen.my_corner_radius);
cardView.setShapeAppearanceModel(
cardView.getShapeAppearanceModel()
.toBuilder()
.setTopLeftCorner(CornerFamily.ROUNDED,radius)
.setTopRightCorner(CornerFamily.ROUNDED,radius)
.setBottomRightCornerSize(0)
.setBottomLeftCornerSize(0)
.build());

enter image description here

关于android - MaterialCardView 的不同角半径值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54688737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com