Simple Line
{
/*Create an array for the points of the line*/
static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240,10} }; // 5个点坐标值
/*Create style*/
static lv_style_t style_line;
lv_style_init(&style_line);
lv_style_set_line_width(&style_line, 8); // 设置线宽
lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_BLUE));//设置线条颜色为蓝色
lv_style_set_line_rounded(&style_line, true); // 使能线条圆角功能
/*Create a line and apply the new style*/
lv_obj_t* line1;
line1 = lv_line_create(lv_scr_act()); // 创建线条对象
lv_line_set_points(line1, line_points, 5); // 设置线条数据点数
lv_obj_add_style(line1, &style_line, 0); // 线条添加style
lv_obj_center(line1); // 居中显示
}
运行效果
- 修改线条颜色为红色
lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_RED));
- 运行效果
- 关闭圆角功能
lv_style_set_line_rounded(&style_line, false);
- 修改线宽为1
lv_style_set_line_width(&style_line, 1);
- 运行效果