gpt4 book ai didi

android - setCornerRadius 不适用于 Android 4.2.2

转载 作者:行者123 更新时间:2023-11-29 01:52:58 29 4
gpt4 key购买 nike

我已经实现了双指缩放以缩放其 subview 具有背景可绘制对象的 ViewGroup。在 onScaleEnd 上,我以新的比例重新绘制 subview ,使它们更清晰。然而,在以较小的比例重新绘制后,圆角半径太大,导致矩形形状出现错误。我有代码可以更改所有形状的角半径,这些形状在我的 Kindle Fire HD(基于 4.0.3)上运行良好,但在我的 Galaxy Nexus (4.2.2) 手机上没有任何作用。

注意:我不会改变可绘制对象,因为我确实希望所有基于该资源的可绘制对象在我这样做时改变它们的外观。

我看过:change corner radius of drawable programmatically和其他几篇文章,但没有任何内容暗示跨设备的不同行为。

代码如下:

    final LayerDrawable layerDrawable = (LayerDrawable) context.getResources().getDrawable(drawableId);
final Drawable drawable = layerDrawable.findDrawableByLayerId(drawableLayerId);
if (drawable instanceof GradientDrawable) {
final float newRadius = nodeScale > SMALL_TREE_NODE_LAYOUT_THRESHOLD ? normalRadius : smallRadius;

// this doesn't work
((GradientDrawable) drawable).setCornerRadius(newRadius);

// this doesn't work either
((GradientDrawable) drawable).setCornerRadii(new float[] {newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius });
}

这是 4.2.2 中的错误吗?

最佳答案

为了解决这个问题,我最终只编写了代码以在需要时重新创建 Drawable。无论如何,这都是更改所有角半径、收缩/增加阴影矩形数量等所必需的。

关于android - setCornerRadius 不适用于 Android 4.2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16863617/

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