gpt4 book ai didi

android - 将 css 渐变转换为 android 渐变 (xml)

转载 作者:太空狗 更新时间:2023-10-29 14:39:25 47 4
gpt4 key购买 nike

我想将 css 渐变转换为 android xml 渐变(形状)文件

例如

background-image: linear-gradient(to right, #ff8177 0%, #ff867a 0%, #ff8c7f 21%, #f99185 52%, #cf556c 78%, #b12a5b 100%);

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="0"
android:endColor="#b12a5b"
android:startColor="#ff867a"
android:type="linear" />
</shape>

我对css了解不多。我只知道 android 并且颜色只有三个参数 android:endColor, android:startColor, android:centerColor 我如何定义这个 %以及CSS中呈现的各种颜色

是否有任何在线工具可以让我通过提供 css 输入来生成 xml 文件。

最佳答案

我建议查看这个相关问题:Using a gradientDrawable with more than three colors set

使用 LinearGradient对象,您可以使用多种颜色和百分比停止定义渐变。

例如(借用我链接的问题):

LinearGradient linearGradient = new LinearGradient(0, 0, width, height,
new int[] {
0xFF1e5799,
0xFF207cca,
0xFF2989d8,
0xFF207cca }, //substitute the correct colors for these
new float[] {
0, 0.40f, 0.60f, 1 },
Shader.TileMode.REPEAT);

我链接的问题和 official documentation包含有关如何使用它的更多详细信息。

关于android - 将 css 渐变转换为 android 渐变 (xml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51005189/

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