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设置颜色的起止位置
735浏览 • 1回复 待解决
linear-gradient不支持start,end属性
758浏览 • 1回复 待解决
3516下载提示node.lib问题
8420浏览 • 2回复 已解决
HarmonyOS ArkUI有哪些类型的Node
193浏览 • 1回复 待解决
k8s 在加入新 node 后的 pod 调度问题
2013浏览 • 1回复 待解决
kubectl get node修改name
2328浏览 • 0回复 待解决
HarmonyOS 启动页设置问题
406浏览 • 1回复 待解决
HarmonyOS Flex 布局设置问题
357浏览 • 1回复 待解决
Task assembleHap not found in hvigor node: entry
1692浏览 • 1回复 待解决
HarmonyOS renderNode的frame设置问题
468浏览 • 1回复 待解决
HarmonyOS scroll的高度设置问题
727浏览 • 1回复 待解决
HarmonyOS Tabs组件bar背景设置问题
281浏览 • 1回复 待解决
HarmonyOS web_view设置超时问题
298浏览 • 1回复 待解决
HarmonyOS 关于代理提醒的设置问题
366浏览 • 1回复 待解决
Node-API的关键交互流程有哪些?
336浏览 • 1回复 待解决
Node-API的组成架构都有哪些?
269浏览 • 1回复 待解决
ConstraintSize尺寸设置问题
454浏览 • 1回复 待解决