HarmonyOS NODE_LINEAR_GRADIENT设置问题

NODE_LINEAR_GRADIENT属性文档如下,但object格式描述不清晰,麻烦提供一下示例。

/**  
     * @brief Sets the gradient attribute, which can be set, reset, and obtained as required through APIs.  
     *  
     * Format of the {@link ArkUI_AttributeItem} parameter for setting the attribute:\n  
     * .value[0].f32: start angle of the linear gradient. A positive value indicates a clockwise rotation from the  
     * origin, (0, 0). The default value is <b>180</b>. \n  
     * .value[1].i32: direction of the linear gradient. It does not take effect when <b>angle</b> is set.  
     * The parameter type is {@link ArkUI_LinearGradientDirection}: \n  
     * .value[2].i32: whether the colors are repeated. The default value is <b>false</b>. \n  
     * .object: array of color stops, each of which consists of a color and its stop position.  
     * Invalid colors are automatically skipped. \n  
     * colors: colors of the color stops. \n  
     * stops: stop positions of the color stops. \n  
     * size: number of colors. \n  
     * \n  
     * Format of the return value {@link ArkUI_AttributeItem}: \n  
     * .value[0].f32: start angle of the linear gradient. \n  
     * .value[1].i32: direction of the linear gradient. It does not take effect when <b>angle</b> is set. \n  
     * .value[0].i32: whether the colors are repeated. \n  
     * .object: array of color stops, each of which consists of a color and its stop position.  
     * Invalid colors are automatically skipped. \n  
     * colors: colors of the color stops. \n  
     * stops: stop positions of the color stops. \n  
     * size: number of colors. \n  
     *  
     */  
    NODE_LINEAR_GRADIENT,
HarmonyOS
2024-10-14 09:33:25
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

可以参考NODE_RADIAL_GRADIENT的方式:

unsigned int colors[] = {0xFFFFFF00, 0xFF0000FF};  
float stops[] = {0.0,0.5};  
ArkUI_ColorStop colorStop = {colors, stops,2};  
ArkUI_ColorStop *ptr = &colorStop;  
ArkUI_NumberValue value[]={{.f32 = 50}, {.f32=50}, {.f32 = 20}, {.i32 = 1}};  
ArkUI_AttributeItem item = {value, sizeof(value)/sizeof(ArkUI_NumberValue),  
                                            .object=reinterpret_cast<void *>(ptr)};  
nodeAPI ->setAttribute(row,NODE_RADIAL_GRADIENT, &item);

对于Linear的场景,可以根据需要调整value的值。

ArkUI_NumberValue value[]={{.f32 = 50}, {.f32=50}, {.f32 = 20}, {.i32 = 1}};
分享
微博
QQ
微信
回复
2024-10-14 16:49:33
相关问题
linear-gradient设置颜色的起止位置
845浏览 • 1回复 待解决
linear-gradient不支持start,end属性
852浏览 • 1回复 待解决
3516下载提示node.lib问题
8592浏览 • 2回复 已解决
k8s 在加入新 node 后的 pod 调度问题
2097浏览 • 1回复 待解决
HarmonyOS 阴影设置问题
29浏览 • 1回复 待解决
HarmonyOS ArkUI有哪些类型的Node
286浏览 • 1回复 待解决
kubectl get node修改name
2408浏览 • 0回复 待解决
HarmonyOS 横竖屏设置问题
24浏览 • 1回复 待解决
HarmonyOS 启动图设置问题
52浏览 • 1回复 待解决
HarmonyOS 启动页设置问题
597浏览 • 1回复 待解决
HarmonyOS 设置横竖屏问题
23浏览 • 1回复 待解决
HarmonyOS 设置屏幕亮度问题
39浏览 • 1回复 待解决
HarmonyOS page设置全屏问题
12浏览 • 1回复 待解决
HarmonyOS Flex 布局设置问题
487浏览 • 1回复 待解决
Task assembleHap not found in hvigor node: entry
1904浏览 • 1回复 待解决
HarmonyOS Web url初始设置问题
28浏览 • 1回复 待解决
HarmonyOS RelativeContainer宽高设置问题
44浏览 • 1回复 待解决
ConstraintSize尺寸设置问题
588浏览 • 1回复 待解决