List Layout容器
List Layout
容器
- List Layout控件时一个容器类,可以将相同类型的自定义的Container集中在一起,并进行上下或左右的滚动。
行为模式
A ListLayout itself does not have any notable impact on performance and is almost entirely dependent on its children. Therefore, the ListLayout is considered a very fast widget on most platforms.
意思是说,ListLayout本身没有什么行为,他只是一个容器,取决于其children的行为模式。
添加child
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <touchgfx/Color.hpp>
Screen1ViewBase::Screen1ViewBase()
{
listLayout1.setDirection(touchgfx::SOUTH);
listLayout1.setXY(90, 111);
//box1.自定义的
box1.setWidth(50);
box1.setHeight(50);
box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
//添加
listLayout1.add(box1);
//在screen1view中添加listlayout1控件
add(listLayout1);
}
属性
List Layout的属性可配置的非常少,原因是他的行为模式并不依赖自身,而是依赖于它装载的“child”。
一般我们只需要设置其Direction属性就好了,South是指上下滚动,East是左右滚动。
发现Location中的W和H是无法设置的,原因是List Layout容器会根据children的尺寸自动调整。
Child的设计
在官方的Demo例程中
主界面
发现在主界面的UI中,在list(List Layout) 控件下,并没有显示的添加ContainListElement,那么程序运行后,生成的界面的内容又是在哪里添加的呢?难道是在代码中显示的添加??
Text Resource
注意到在Text下的 Resource中有很多Resource ID,正好以list_element_xx开头,我们会在Generate Code中发现,这些Resource ID变成了“T_LIST_ELEMENT_xx”
且上述枚举定义在“TextKeysAndLanguages.hpp”中
Image Resource
每个图片在“BitmapDatabase.hpp”中会有一个宏定义来标识这些图片,当程序中需要使用某个图片时,
使用如下片段就可以了
//BitmapDatabase.hpp
const uint16_t BITMAP_ICON0_ID = 3;
const uint16_t BITMAP_ICON1_ID = 4;
const uint16_t BITMAP_ICON2_ID = 5;
const uint16_t BITMAP_ICON3_ID = 6;
const uint16_t BITMAP_ICON4_ID = 7;
const uint16_