EFL优化篇:优化Tizen本机应用程序
本教程演示了如何优化Tizen本机应用程序。热身熟悉Edje、 Elementary和eva API通过学习基本知识:优化EDC
优化EDC代码。优化eva
优化eva代码。
优化EDC
优化EDC:
[*]删除不必要的部分。当您创建EDC,过时的和不必要的部分。 因为他们对性能有影响,移除它们。
[*]删除不必要的部分。当您创建EDC,过时的和不必要的部分。 因为他们对性能有影响,移除它们。
前后
<font size="3">collections
{
group
{
name: "main";
parts
{
part
{
name: "bg";
type: RECT;
description
{
state: "default" 0.0;
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 1.0;
color: 255 255 255 255;
}
}
part
{
name: "new";
type: RECT;
scale: 1;
mouse_events: 1;
description
{
state: "default" 0.0;
color: 255 255 0 255;
rel1.relative: 0.2 0.2;
rel2.relative: 0.8 0.8;
}
}
part
{
name: "old";
type: RECT;
scale: 1;
mouse_events: 1;
description
{
state: "default" 0.0;
color: 0 0 0 0;
rel1.relative: 0.5 0.5;
rel2.relative: 1.0 1.0;
}
}
}
}
}</font>
<font size="3">collections
{
group
{
name: "main";
parts
{
part
{
name: "bg";
type: RECT;
description
{
state: "default" 0.0;
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 1.0;
color: 255 255 255 255;
}
}
part
{
name: "new";
type: RECT;
scale: 1;
mouse_events: 1;
description
{
state: "default" 0.0;
color: 255 255 0 255;
rel1.relative: 0.2 0.2;
rel2.relative: 0.8 0.8;
}
}
}
}
}</font>
[*]使用文本,如果可能的话,而不是Textblock。
以下edc导致相同的结果。 然而,使用文本为高性能除了使用简单的文本标签或多个行。
前后
<font size="3">collections
{
styles
{
style
{
name: "text_style";
base: "font="Sans" font_size=30 text_class=entry
color=#0088AA style=shadow,bottom
shadow_color=#00000080 valign=0.5 ellipsis=1.0
wrap=none align=center";
}
}
group
{
name: "main";
parts
{
part
{
name: "text";
type: TEXTBLOCK;
scale: 1;
description
{
state: "default" 0.0;
text
{
style: "text_style";
text: "TEXT";
}
}
}
}
}
}</font>
<font size="3">collections
{
group
{
name: "main";
part
{
name: "simple";
type: TEXT;
scale: 1;
effect: SHADOW;
description
{
state: "default" 0.0;
align: 0.5 0.5;
color: 0 136 170 255;
visible: 1;
text
{
size: 30;
font: "Sans";
text: "TEXT";
}
}
}
}
}</font>
3.压缩图片和你的图片嵌入到EDC。
当你使用一个固定的形象,这是更有效的EDC内调用一个图像。 这节省时间在获得图像数据和更适合的数据大小。
<font size="3">collections
{
images
{
image: "logo.png" COMP;
}
group
{
name: "main";
parts
{
part
{
name: "logo";
type: IMAGE;
description
{
state: "default" 0.0;
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 1.0;
image.normal: "logo.png";
aspect: 1 1;
aspect_preference: BOTH;
}
}
}
}
}</font>
4.如果可能的话,使用间隔部分。
当你使用(如填充部分)是无形的,但有一个大小,使用间隔更有效率。 由于垫片是无形的,它没有可见的和颜色选项。
前后
<font size="3">collections
{
group
{
name: "main";
parts
{
part
{
name: "bg";
type: RECT;
description
{
state: "default" 0.0;
color: 255 255 255 255;
}
}
part
{
name: "padding_left_top";
type: RECT;
description
{
state: "default" 0.0;
color: 0 0 0 0;
rel1.to: "bg";
rel2.to:"bg";
rel2.relative: 0.0 0.0;
align: 0.0 0.0;
min: 100 100;
}
}
part
{
name: "padding_right_bottom";
type: RECT;
description
{
state: "default" 0.0;
color: 0 0 0 0;
rel1.to: "bg";
rel1.relative: 1.0 1.0;
rel2.to:"bg";
align: 1.0 1.0;
min: 100 100;
}
}
part
{
name: "content";
type: RECT;
description
{
state: "default" 0.0;
color: 255 255 0 255;
rel1.to: "padding_left_top";
rel1.relative: 1.0 1.0;
rel2.to:"padding_right_bottom";
rel2.relative: 0.0 0.0;
}
}
}
}
}</font>
<font size="3">collections
{
group
{
name: "main";
parts
{
part
{
name: "bg";
type: RECT;
description
{
state: "default" 0.0;
color: 255 255 255 255;
}
}
part
{
name: "padding_left_top";
type: SPACER;
description
{
state: "default" 0.0;
rel1.to: "bg";
rel2.to:"bg";
rel2.relative: 0.0 0.0;
align: 0.0 0.0;
min: 100 100;
}
}
part
{
name: "padding_right_bottom";
type: SPACER;
description
{
state: "default" 0.0;
rel1.to: "bg";
rel1.relative: 1.0 1.0;
rel2.to:"bg";
align: 1.0 1.0;
min: 100 100;
}
}
part
{
name: "content";
type: RECT;
description
{
state: "default" 0.0;
color: 255 255 0 255;
rel1.to: "padding_left_top";
rel1.relative: 1.0 1.0;
rel2.to:"padding_right_bottom";
rel2.relative: 0.0 0.0;
}
}
}
}
}</font>
5.使用图像边界特性。
当你使用一个图像,您不需要使用一个完整的尺寸或更大尺寸的形象。 正如您将在下面看到的,它是更有效规模图像使用边界选项。
之前后
前后
<font size="3">collections
{
images
{
image: "test.png" COMP;
}
group
{
name: "main";
parts
{
part
{
name: "test";
type: IMAGE;
description
{
state: "default" 0.0;
rel1.relative: 0.2 0.2;
rel2.relative: 0.8 0.8;
image.normal: "test.png";
}
}
}
}
}</font>
<font size="3">collections
{
images
{
image: "test.png" COMP;
}
group
{
name: "main";
parts
{
part
{
name: "test";
type: IMAGE;
description
{
state: "default" 0.0;
rel1.relative: 0.2 0.2;
rel2.relative: 0.8 0.8;
image.normal: "test.png";
image.border: 5 5 5 5;
}
}
}
}
}</font>
https://developer.tizen.org/sites/default/files/dev_guide/org.tizen.tutorials/images/image_after.pnghttps://developer.tizen.org/sites/default/files/dev_guide/org.tizen.tutorials/images/image_before.png
优化eva优化eva:
[*]使用矩形对象,而不是使用纯色图像。当你需要一个坚实的颜色对象,它是更好的(更有效率)使用一个矩形比图像对象。
之前后
<font size="3">image = elm_image_add(win);
snprintf(buf, sizeof(buf), "%s/images/white_bg.png", elm_app_data_dir_get());
elm_image_file_set(image, buf, NULL);
evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, image);
evas_object_show(image);</font>
<font size="3">rect = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_color_set(rect, 255, 255, 255, 255);
evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, rect);
evas_object_show(rect);</font>
2.使物体隐形,而不是设置α为0。使物体隐形,更高效的使用 evas_object_hide () 而不是改变alpha值为0。
之前后
<font size="3">static void
_invisible_cb(void *data, Evas_Object *obj, void *ev)
{
evas_object_color_set(obj, 0, 0, 0, 0);
}</font>
<font size="3">static void
_invisible_cb(void *data, Evas_Object *obj, void *ev)
{
evas_object_hide(obj);
}</font>
3.如果你需要最大的优化,使用 evas_object_image 而不是 elm_image 和 elm_icon 。
之前后
<font size="3"><div class="blockcode"><blockquote>
之前 后
static void
_invisible_cb(void *data, Evas_Object *obj, void *ev)
{
evas_object_color_set(obj, 0, 0, 0, 0);
}
static void
_invisible_cb(void *data, Evas_Object *obj, void *ev)
{
evas_object_hide(obj);
}
</font>
<font size="3"><div class="blockcode"><blockquote>img = evas_object_image_add(evas_object_evas_get(parent));
snprintf(buf, sizeof(buf), "%s/images/white_bg.png", elm_app_data_dir_get());
evas_object_image_file_set(img, buf, NULL);
evas_object_image_filled_set(img, EINA_TRUE);
evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(img);</font>
4.正确设置家长为了避免初等树重建。
创建一个对象之前,确保父母和孩子之间的关系是正确设置为了避免以后重建。
之前后
<font size="3">win = elm_win_add();
scroller = elm_scroller_add(win);
box = elm_box_add(win);
button = elm_button_add(win);</font>
<font size="3">win = elm_win_add();
scroller = elm_scroller_add(win);
box = elm_box_add(scroller);
button = elm_button_add(box);</font>
页:
[1]