gpt4 book ai didi

android - 换个角不画背景?

转载 作者:行者123 更新时间:2023-11-29 20:59:38 27 4
gpt4 key购买 nike

我想创建一个有不同角的 View ,形状的xml如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

<solid android:color="#01A2EA" />

<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:radius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />

</shape>

它在蓝色背景下表现良好,但在我更改了四个角半径中的两个之后:

<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:radius="30dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />

它失去了背景颜色,我什么也看不见。

API 文档说:

Note: Every corner must (initially) be provided a corner radius greater than 1, or else no corners are rounded. If you want specific corners to not be rounded, a work-around is to use android:radius to set a default corner radius greater than 1, but then override each and every corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.

但它似乎不能与背景一起正常工作?

最佳答案

是的,你是对的,有一个错误,但你可以这样解决它。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

<solid android:color="#01A2EA" />

<corners
android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topRightRadius="0.1dp"
android:topLeftRadius="0.1dp"/>
</shape>

注意:

这可能不会反射(reflect)在设计时。所以请运行代码看看效果。

关于android - 换个角不画背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26500932/

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