基础组件模型

公共属性组件模型的通用属性定义

虚拟view与实体view

​ 虚拟view,即view的内容直接通过宿主的canvas绘制出来,它本身并不需要一个实体的view存在,在真实的view tree中,是看不到这个实例,只能看到其宿主的存在。它包括:原子虚拟view组件比如文本、图片、线条,布局虚拟view组件比如线性布局、帧布局等。虚拟view也遵循Android绘制view的逻辑,需要响应measure、layout、draw的过程才能显示。实体view,即原生的native view。

属性

名称 类型 默认值 描述 表达式
id int 0 组件id
layoutWidth int float enum:   match_parent   wrap_content 0 组件的布局宽度,与Android里的概念类似,写绝对值的时候表示绝对宽高,match_parent表示尽可能撑满父容器提供的宽高,wrap_content表示根据自身内容的宽高来布局
layoutHeight int float enum:   match_parent   wrap_content 0 组件的布局宽度,与Android里的概念类似,写绝对值的时候表示绝对宽高,match_parent表示尽可能撑满父容器提供的宽高,wrap_content表示根据自身内容的宽高来布局
layoutGravity left 、right 、top 、bottom、v_center 、h_center left|top 描述组件在容器中的对齐方式,left:靠左,right:靠右,top:靠上,bottom:靠底,v_center:垂直方向居中,h_center:水平方向居中,可用组合描述
autoDimX int float 1 组件宽高比计算的横向值
autoDimY int float 1 组件宽高比计算的竖向值
autoDimDirection X 、 Y 、 NONE NONE 组件在布局中的基准方向,用于计算组件的宽高比,与autoDimX、autoDimY配合使用,设置了这三个属性时,在计算组件尺寸时具有更高的优先级。当autoDimDirection=X时,组件的宽度由layoutWidth和父容器决策决定,但高度 = width * (autoDimY / autoDimX),当autoDimDirection=Y时,组件的高度由layoutHeight和父容器决策决定,但宽度 = height * (autoDimX / autoDimY)
minWidth(iOS暂未支持) int float 0 最小宽度
minHeight(iOS暂未支持) int float 0 最小高度
padding int float 0 同时设置 4 个内边距
paddingLeft int float 0 左内边距,优先级高于 padding
paddingRight int float 0 右内边距,优先级高于 padding
paddingTop int float 0 上内边距,优先级高于 padding
paddingBottom int float 0 下内边距,优先级高于 padding
layoutMargin int float 0 同时设置 4 个外边距(ios不支持,使用单个边距)
layoutMarginLeft int float 0 左外边距,优先级高于 layoutMargin
layoutMarginRight int float 0 右外边距,优先级高于 layoutMargin
layoutMarginTop int float 0 上外边距,优先级高于 layoutMargin
layoutMarginBottom int float 0 下外边距,优先级高于 layoutMargin
background int 0 背景色
borderWidth int float 0 边框宽度
borderColor int 0 边框颜色
borderRadius int float 0 边框四个角的圆角半径,与 borderWidth 配合使用,支持NText、VText、VHLayout、VH2Layout、FrameLayout、GridLayout
borderTopLeftRadius int float 0 单独设置左上角圆角半径,使用同上(iOS仅Layout支持单独设置),优先级高于 borderRadius
borderTopRightRadius int float 0 单独设置右上角圆角半径,使用同上(iOS仅Layout支持单独设置),优先级高于 borderRadius
borderBottomLeftRadius int float 0 单独设置左下角圆角半径,使用同上(iOS仅Layout支持单独设置),优先级高于 borderRadius
borderBottomRightRadius int float 0 单独设置右下角圆角半径,使用同上(iOS仅Layout支持单独设置),优先级高于 borderRadius
visibility visible 、invisible、 gone visible 可见性,与Android里的概念类似,visible:可见,invisible:不可见,但占位,gone:不可见也不占位
dataTag string 组件数据标识
flag flag_software   flag_exposure   flag_clickable   flag_longclickable   flag_touchable 组件行为定义 flag_software:关闭view的硬件加速,flag_exposure:需要触发曝光事件,flag_clickable:需要响应点击事件,flag_longclickable:需要响应长按事件,flag_touchable:需要响应触摸事件
action string null (表示点击事件触发之后跳转到数据中action字段定义的页面)
class string null 跟组件绑定的逻辑处理对象名称

数值单位

​ 在组件属性里,跟尺寸相关的属性,其值的单位默认是dp,比如layoutWidth=10,表示宽度是10dp;实际值 = dp * density;

为了更精准地适配视觉,支持rp单位,表示适配屏幕大小的值,比如layoutWidth=10rp,实际值 = 10 * 屏幕宽度 / 750;这里 750 指的是设计稿里的屏幕宽度,默认值是 750,可以通过 com.libra.Utils.setUedScreenWidth() 方法修改默认值。

颜色值

在组件颜色相关属性里,支持16进制数表示,#RRGGBB、#AARRGGBB,也支持以下几个颜色文本:

black blue cyan dkgray gray green
ltgray magenta red transparent yellow

原子组件

基础元素叶子节点组件,不能嵌套其他组件。

NText

原生实现的文本组件,通过模板里定义可绑定以下属性:字体颜色、字号大小、字体粗细、支持文本对齐,行数,最大行数,行间距,行间距系数,截断方式。

名称 类型 默认值 描述 表达
text string 文本内容
textColor int 黑色 字体颜色
textSize int/float 20dp 字号大小
textStyle enum(normal/bold/italic/strike/underline) normal normal:默认样式,bold:加粗,itlaic:斜体,strike:删除线,underline:下划线
ellipsize enum(none/start/marquee/middle/end) none 截断方式(iOS不支持走马灯)
lines int 1 固定行数,设为0表示不固定行数(ios不支持)
maxLines int 最大行数,需要配合lines=0使用
lineSpaceMultiplier(iOS暂不支持) int/float 1 行高放大系数,每一行文本高度计算会乘以这个系数
lineSpaceExtra(iOS暂不支持) int/float 0 行高额外空间,每一行文本高度计算会加上这个值
supportHTMLStyle(iOS不支持) boolean false true:采用富文本方式加载,false:按照普通文本加载
gravity enum(left/right/top/bottom/v_center/h_center) left|top 描述内容的对齐,比如文字在文本组件里的位置、原子组件在容器里的位置,left:靠左,right:靠右,top:靠上,bottom:靠底,v_center:垂直方向居中,h_center:水平方向居中,可用组合描述(iOS暂只支持水平方向)

VText

虚拟化实现的文本组件,精简了大量原生文本的特性,只支持以下几个特性:字体颜色、字号大小、字体粗细、支持文本对齐,只能单行显示,不支持分多行。不支持响应点击事件。不支持click、longclick。

名称 类型 默认值 描述 表达式
text string 文本内容
textColor int 黑色 字体颜色
textSize int/float 20dp 字号大小
textStyle norma、bold
、italic、strike
normal normal:默认样式,bold:加粗,itlaic:斜体,strike:删除线
gravity left、right
、top、bottom
、v_center、h_center
left|top 描述内容的对齐,比如文字在文本组件里的位置、原子组件在容器里的位置,left:靠左,right:靠右,top:靠上,bottom:靠底,v_center:垂直方向居中,h_center:水平方向居中,可用组合描述(iOS暂只支持水平方向)
<VText
    id="1"
    text="title"
    textSize="12"
    textColor="#333333"
    layoutWidth="wrap_content"
    layoutHeight="wrap_content" />

PiImageView

扩展原生图片,支持 Gif 动图、本地图片、网络图片,所有 .out 中的图片显示,均使用此组件,七巧板推荐的图片组件,将不再支持。

imageData

名称 类型 默认值 描述
isLocal boolean false 是否为本地图片
isGif boolean false 是否为 Gif 动图
imgSrc string null 图片地址,支持本地、网络、附件 Id 加载。
imgRadius int 0 图片圆角大小
<PiImageView
    layoutGravity="v_center"
    layoutHeight="12"
    layoutWidth="12"
    layoutMarginRight="16"
    imgRadius="2"
    isLocal="true"
    imgSrc="${imgSwitch}"/>
{
"imgSwitch":"core_arrow_right_blue",
}
``

## NLine

实体进度条组件,支持实线、虚线,可以使用横向显示、竖向显示。**不支持click、longclick。**

| 名称                    | 类型                                              | 默认值       | 描述                                                         | 表达式 |
| ----------------------- | ------------------------------------------------- | ------------ | ------------------------------------------------------------ | ------ |
| color                   | string                                            | black        | 线条颜色                                                     | 是     |
| paintWidth              | int                                               | 1            | 线条宽度                                                     | 否     |
| orientation             | enum(H/V)                                         | H            | 线条方向,H:横向,V:竖向                                   | 否     |
| style(iOS暂不支持)      | enum(solid/dash)                                  | solid        | 线条样式,solid:实线,dash:虚线                            | 否     |
| dashEffect(iOS暂不支持) | string                                            | [3, 5, 3, 5] | 虚线样式数组,元素必须是偶数个,以实线宽度-虚线宽度…的顺序写 | 否     |
| gravity                 | left、right、top、bottom<br/>、v_center、h_center | left\|top    | 描述内容的对齐,比如文字在文本组件里的位置、原子组件在容器里的位置,left:靠左,right:靠右,top:靠上,bottom:靠底,v_center:垂直方向居中,h_center:水平方向居中,可用`或`组合描述 ||

```xml
<NLine
    layoutWidth="match_parent"
    layoutHeight="0.5"
    paintWidth="0.5"
    orientation="H"
    style="dash"
    dashEffect="[10,6,10,6]"
    color="#D0D0D0" />

VLine

虚拟化线条,支持实线、虚线,可以使用横向显示、竖向显示。不支持click、longclick。

名称 类型 默认值 描述 表达式
color string black 线条颜色
paintWidth int 1 线条宽度
orientation enum(H/V) H 线条方向,H:横向,V:竖向
style(iOS暂不支持) enum(solid/dash) solid 线条样式,solid:实线,dash:虚线
dashEffect(iOS暂不支持) string [3, 5, 3, 5] 虚线样式数组,元素必须是偶数个,以实线宽度-虚线宽度…的顺序写
gravity left、right、top、bottom
、v_center、h_center
left|top 描述内容的对齐,比如文字在文本组件里的位置、原子组件在容器里的位置,left:靠左,right:靠右,top:靠上,bottom:靠底,v_center:垂直方向居中,h_center:水平方向居中,可用组合描述

容器组件

Page

翻页滚动的组件,与ScrollerSlider的区别在于它是有页面效果,一页一页滚动,而ScrollerSlider是可连续滚动。

名称 类型 默认值 描述 表达式
orientation enum(H/V) V 滚动方向,H:水平滚动,V:垂直滚动
onPageFlip(iOS暂不支持) expr 表达式,翻页的时候触发加载的逻辑
autoSwitch boolean false true:自动翻页滚动,false:不自动滚动
canSlide boolean true true:响应手势滑动,false:不响应手势滑动
stayTime int 2000 单位ms,自动滚动的间隔
autoSwitchTime int 500 单位ms,滚动时动画的持续时间
dataTag jsonArray 容器内组件数据,描述内部子组件的类型与数据
animatorTime(iOS不支持) int 100 单位ms,手势滑动时,松手后复位或者滚动到下一页的动画时间
layoutOrientation(iOS不支持) enum(normal/reverse) normal 水平滚动:normal是从左往右布局,reverse是从右往左布局;垂直滚动:normal是从上往下布局,reverse是从下往上布局
animationStyle(iOS不支持) enum(linear/decelerate/accelerate/accelerateDecelerate/spring) linear 线性、减速、加速、先加速后减速、弹簧
<Page
    autoSwitch="true"
    dataTag="vList"
    stayTime="2500"
    canSlide="false"
    orientation="V"
    layoutRatio="1"
    layoutWidth="0"
    layoutHeight="33.5" />

FrameLayout

虚拟化的帧布局,主要提供了布局协议,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。

<FrameLayout
    flag="flag_draw"
    dataTag="container"
    layoutWidth="match_parent"
    layoutHeight="wrap_content">
    <VHLayout
        orientation="V"
        layoutWidth="match_parent"
        layoutHeight="wrap_content">
        <TMNImage
            flag="flag_draw|flag_event|flag_exposure|flag_clickable"
            id="0"
            dataTag="header"
            action="action"
            layoutWidth="match_parent"
            layoutHeight="wrap_content"
            autoDimDirection="X"
            autoDimX="750"
            autoDimY="110"/>

        <Grid
            dataTag="vList"
            colCount="2"
            layoutWidth="match_parent"
            layoutHeight="wrap_content" />
    </VHLayout>
</FrameLayout>

RatioLayout

虚拟化的线性布局,其子组件支持写layoutRatio属性来声明在父容器空间上占用的比例,声明过layoutRatio的组件按比例分配宽或高,未声明layoutRatio的组件占用剩余的空间。不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。

名称 类型 默认值 描述 表达式
orientation enum(H/V) H 水平方向布局,垂直方向布局
layoutRatio int/float 0.0 在水平方向或者垂直方向的权重。这是个在基础元素上就有的属性,但是只有RatioLayout会使用它
<RatioLayout
        flag="flag_draw|flag_event|flag_exposure|flag_clickable"
        action="action"
        orientation="V"
        layoutWidth="wrap_content"
        layoutHeight="match_parent">
    <RatioLayout
            orientation="H"
            layoutWidth="wrap_content"
            layoutMarginBottom="1.5"
            layoutRatio="1"
            layoutHeight="0"
            flag="flag_draw">
        <VText
                dataTag="title1"
                textSize="12"
                textColor="#333333"
                layoutGravity="v_center"
                layoutRatio="1"
                layoutWidth="wrap_content"
                layoutHeight="wrap_content"
                ellipsize="end"/>
    </RatioLayout>

    <RatioLayout
            orientation="H"
            layoutWidth="wrap_content"
            layoutMarginTop="1.5"
            gravity="v_center"
            layoutRatio="1"
            layoutHeight="0"
            flag="flag_draw">
        <VText
                dataTag="title2"
                textSize="12"
                textColor="#333333"
                layoutGravity="v_center"
                layoutRatio="1"
                layoutWidth="wrap_content"
                layoutHeight="wrap_content"
                ellipsize="end"/>
    </RatioLayout>

</RatioLayout>

Grid

实体网格布局容器,支持通过数据动态创建子组件。

名称 类型 默认值 描述 表达式
colCount int 2 列数
itemHeight int/float 0 组件的高度,当itemHeight =0时,采用wrap_content的方式计算组件高度
itemVerticalMargin int/float false 垂直间距,即行之间的间距
itemHorizontalMargin int/float 0 水平间距,即列之间的间距
dataTag jsonArray 容器内组件数据,描述内部子组件的类型与数据
<Grid
    dataTag="vList"
    colCount="2"
    layoutWidth="match_parent"
    layoutHeight="wrap_content"/>

GridLayout

虚拟化的网格布局,与Grid的区别是它是虚拟的,主要提供了布局协议,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。

名称 类型 默认值 描述 表达式
colCount int 2 列数
itemHeight int 0 组件的高度
itemVerticalMargin int/float 0 垂直间距,即行之间的间距
itemHorizontalMargin int/float 0 水平间距,即列之间的间距
<GridLayout
  colCount="2"
  layoutWidth="match_parent"
  layoutHeight="wrap_content"
  itemHorizontalMargin="5"
  itemVerticalMargin="5"
  background="#FFFFFF"
  paddingTop="7"
  paddingRight="7"
  paddingBottom="7"
  paddingLeft="7">
  <TMNImage
    layoutWidth="match_parent"
    layoutHeight="70"
    ratio="1"
    scaleType="center_crop"
    src="${data[0]}"/>
  <TMNImage
    layoutWidth="match_parent"
    layoutHeight="70"
    ratio="1"
    scaleType="center_crop"
    src="${data[3]}"/>
  </GridLayout>

VH2Layout

虚拟化的线性布局,与VHLayout的区别是它支持子组件分别从top、left、right、bottom四个方向进行布局。不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。

名称 类型 默认值 描述 表达式
orientation enum(H/V) H 水平方向布局,垂直方向布局
layoutDirection enum(left/top/right/bottom) left 当oriention=H时,支持组件分布从left与right两个方向布局,这样可以实现靠左、靠右的效果;当orientation=V时,支持组件分布从top与bottom两个方向布局,这样可以实现靠上、靠下的效果;默认值是left,在orientation=V的情况下,必须显示指定top或者bottom。这是个基础组件就有的属性,但是只有VH2Layout会去使用它
<VH2Layout
    flag="flag_draw"
    layoutWidth="match_parent"
    layoutHeight="wrap_content"
    layoutRatio="74">
    <VText
        layoutWidth="wrap_content"
        layoutHeight="wrap_content"
        dataTag="price"
        textSize="15"
        textStyle="bold"
        layoutMarginLeft="12"
        layoutGravity="left|v_center"
        textColor="#231F1F"/>
    <NImage
        id="2"
        action="cart"
        dataTag="shopCart"
        flag="flag_event|flag_clickable"
        scaleType="fit_xy"
        layoutWidth="19"
        layoutHeight="19"
        layoutMarginRight="12"
        layoutGravity="right|v_center"
        layoutDirection="right"
        src="tm_homepage_shopping_cart"/>
</VH2Layout>

VHLayout

虚拟化的线性布局,与VH的区别是它是虚拟的,主要提供了布局协议,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。

名称 类型 默认值 描述 表达式
orientation enum(H/V) H 水平方向布局,垂直方向布局
<VHLayout
     orientation="V"
    layoutWidth="match_parent"
    layoutHeight="wrap_content">
    <VText
        id="1"
        dataTag="title"
        textSize="12"
        textColor="#333333"
        layoutWidth="wrap_content"
        layoutHeight="wrap_content" />
    <VText
        id="2"
        dataTag="title"
        textSize="12"
        textColor="#333333"
        layoutWidth="wrap_content"
        layoutHeight="wrap_content" />
</VHLayout>

NFrameLayout

实体的帧布局,主要提供了布局协议,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。虚拟的子组件会绘制到它的 canvas 上而不是整个大容器的 canvas,实体的子组件也会添加到它内部,因此在 borderRadius 属性的作用下会裁剪内部区域,除此之外与 FrameLayout 的功能完全一致。

<NFrameLayout
    flag="flag_draw"
    dataTag="container"
    layoutWidth="match_parent"
    layoutHeight="wrap_content">
    <VHLayout
        orientation="V"
        layoutWidth="match_parent"
        layoutHeight="wrap_content">
        <TMNImage
            flag="flag_draw|flag_event|flag_exposure|flag_clickable"
            id="0"
            dataTag="header"
            action="action"
            layoutWidth="match_parent"
            layoutHeight="wrap_content"
            autoDimDirection="X"
            autoDimX="750"
            autoDimY="110"/>

        <Grid
            dataTag="vList"
            colCount="2"
            layoutWidth="match_parent"
            layoutHeight="wrap_content" />
    </VHLayout>
</NFrameLayout>

NRatioLayout

实体的线性布局,其子组件支持写 layoutRatio 属性来声明在父容器空间上占用的比例,声明过layoutRatio的组件按比例分配宽或高,未声明 layoutRatio 的组件占用剩余的空间。不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。虚拟的子组件会绘制到它的 canvas 上而不是整个大容器的 canvas,实体的子组件也会添加到它内部,因此在 borderRadius 属性的作用下会裁剪内部区域,除此之外与 RatioLayout 的功能完全一致。

名称 类型 默认值 描述 表达式
orientation enum(H/V) H 水平方向布局,垂直方向布局
layoutRatio int/float 0.0 在水平方向或者垂直方向的权重。这是个在基础元素上就有的属性,但是只有RatioLayout会使用它
 <NRatioLayout
            orientation="H"
            layoutWidth="wrap_content"
            layoutMarginBottom="1.5"
            layoutRatio="1"
            layoutHeight="0"
            flag="flag_draw">
        <VText
                dataTag="title1"
                textSize="12"
                textColor="#333333"
                layoutGravity="v_center"
                layoutRatio="1"
                layoutWidth="wrap_content"
                layoutHeight="wrap_content"
                ellipsize="end"/>
    </NRatioLayout>

NGridLayout

实体的网格布局,主要提供了布局协议,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。虚拟的子组件会绘制到它的 canvas 上而不是整个大容器的 canvas,实体的子组件也会添加到它内部,因此在 borderRadius 属性的作用下会裁剪内部区域,除此之外与 GridLayout 的功能完全一致。

名称 类型 默认值 描述 表达式
colCount int 2 列数
itemHeight int 0 组件的高度
itemVerticalMargin int/float 0 垂直间距,即行之间的间距
itemHorizontalMargin int/float 0 水平间距,即列之间的间距
<NGridLayout
  colCount="2"
  layoutWidth="match_parent"
  layoutHeight="wrap_content"
  itemHorizontalMargin="5"
  itemVerticalMargin="5"
  background="#FFFFFF"
  paddingTop="7"
  paddingRight="7"
  paddingBottom="7"
  paddingLeft="7">
  <TMNImage
    layoutWidth="match_parent"
    layoutHeight="70"
    ratio="1"
    scaleType="center_crop"
    src="${data[0]}"/>
  <TMNImage
    layoutWidth="match_parent"
    layoutHeight="70"
    ratio="1"
    scaleType="center_crop"
    src="${data[1]}"/>
  </NGridLayout>

NVH2Layout

实体的线性布局,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。虚拟的子组件会绘制到它的 canvas 上而不是整个大容器的 canvas,实体的子组件也会添加到它内部,因此在 borderRadius 属性的作用下会裁剪内部区域,除此之外与 VH2Layout 的功能完全一致。

名称 类型 默认值 描述 表达式
orientation enum(H/V) H 水平方向布局,垂直方向布局
layoutDirection enum(left/top/right/bottom) left 当oriention=H时,支持组件分布从left与right两个方向布局,这样可以实现靠左、靠右的效果;当orientation=V时,支持组件分布从top与bottom两个方向布局,这样可以实现靠上、靠下的效果;默认值是left,在orientation=V的情况下,必须显示指定top或者bottom。这是个基础组件就有的属性,但是只有VH2Layout会去使用它
<NVH2Layout
    flag="flag_draw"
    layoutWidth="match_parent"
    layoutHeight="wrap_content"
    layoutRatio="74">
    <VText
        layoutWidth="wrap_content"
        layoutHeight="wrap_content"
        dataTag="price"
        textSize="15"
        textStyle="bold"
        layoutMarginLeft="12"
        layoutGravity="left|v_center"
        textColor="#231F1F"/>
    <NImage
        id="2"
        action="cart"
        dataTag="shopCart"
        flag="flag_event|flag_clickable"
        scaleType="fit_xy"
        layoutWidth="19"
        layoutHeight="19"
        layoutMarginRight="12"
        layoutGravity="right|v_center"
        layoutDirection="right"
        src="tm_homepage_shopping_cart"/>
</NVH2Layout>

NVHLayout

实体的线性布局,主要提供了布局协议,不支持通过数据动态创建子组件,需要在布局模板里直接写子组件。虚拟的子组件会绘制到它的 canvas 上而不是整个大容器的 canvas,实体的子组件也会添加到它内部,因此在 borderRadius 属性的作用下会裁剪内部区域,除此之外与 VHLayout 的功能完全一致。

名称 类型 默认值 描述 表达式
orientation enum(H/V) H 水平方向布局,垂直方向布局
<NVHLayout
     orientation="V"
    layoutWidth="match_parent"
    layoutHeight="wrap_content">
    <VText
        id="1"
        dataTag="title"
        textSize="12"
        textColor="#333333"
        layoutWidth="wrap_content"
        layoutHeight="wrap_content" />
    <VText
        id="2"
        dataTag="title"
        textSize="12"
        textColor="#333333"
        layoutWidth="wrap_content"
        layoutHeight="wrap_content" />
</NVHLayout>
文档更新时间: 2021-05-12 18:32   作者:陈冕