DuiLib 四 . XML布局

外部应该使用一个垂直布局VerticalLayout
而标题栏里面是从左到右的一个水平布局 HorizontalLayout
可以通过 height 属性指定 HorizontalLayout 的高度。

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<Window size="640,480" caption="0,0,0,35">
  <VerticalLayout>
    <!--标题栏-->
    <HorizontalLayout height="35" bkcolor="#FFD6DBE9">
      <Control bkimage="logo.png" height="32" width="32" />
      <Label text="duilib tutorial" />
    </HorizontalLayout>
    <!--窗口内容区域-->
    <HorizontalLayout bkcolor="#FF4D6082">
      
    </HorizontalLayout>
  </VerticalLayout>
</Window>

bkcolor 属性指定了标题栏的背景色,

2、内外边距
标题栏高度是 35,而 logo 的高度是 32,我们让 logo 图像的上方和左侧分别向下和向右移动 7~9 像素,这样 logo就可以居中显示了。通过 padding 属性可以指定容器的外边距,这里要注意,不像 Web 前端一样使用的是 margin,刚切换过来的朋友可能容易出错,所以要尤其注意。我们通过指定 padding="8,8,0,0" 的方式,指定了 logo文件左边和上边分别有 4 个像素的边距,代码如下:

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<Window size="640,480" caption="0,0,0,35">
  <VerticalLayout>
    <!--标题栏-->
    <HorizontalLayout height="35" bkcolor="#FFD6DBE9">
      <Control bkimage="logo.png" height="32" width="32" padding="4,4,0,0"/>
      <Label text="duilib tutorial" />
    </HorizontalLayout>
    <!--窗口内容区域-->
    <HorizontalLayout bkcolor="#FF4D6082">
      
    </HorizontalLayout>
  </VerticalLayout>
</Window>

padding 的 4 个参数顺序分别是 左、上、右、下

相关推荐
hashiqimiya1 天前
每日android布局xml文件
android·xml·gitee
2601_961194021 天前
27考研资料|百度网盘|夸克网盘
android·xml·考研·ios·iphone·xcode·webview
许彰午4 天前
在PowerBuilder里手写XML序列化——没有现成库的年代怎么拼报文
xml·linux·服务器
坚果的博客5 天前
鸿蒙PC三方库适配OAT.xml 与 SHA512SUM 解读:开源合规与源码校验
xml·开源·harmonyos
奇树谦5 天前
YAML、XML、JSON、TOML、INI、CSV 全面对比:配置文件和数据交换到底该怎么选?
xml·json
南山丶无梅落6 天前
XXE漏洞
xml·漏洞·xxe·网安
小书房6 天前
Android UI为什么由XML转向Compose
xml·ui·compose·声明式ui
学编程的小程6 天前
配置范式演进:XML、JavaConfig 与 Spring Boot
xml·spring boot·后端
le1616167 天前
Android Compose基础布局——从传统XML的视角切入了解
xml·compose
XiYang-DING8 天前
【MyBatis】XML方式实现CRUD
xml·mybatis