【HarmoryOS开发】页面布局及列表的使用

一、列表的使用

1.页面结构注意事项

  1. 页面结构使用 HTML 相同的标签进行嵌套,最外层是 div 容器。
  2. 文本内容放在<text>标签中才能呈现,否则不会呈现文本内容。
  3. 可以直接调用 鸿蒙 JS 封装好的 组件。
<div class="container">
    <text class="title">待办事项</text>
    <div class="item">
        <text class="todo">8点产品需求会议</text>
        <switch showtext="true" checked="true"
                texton="完成" textoff="待办"
                class="switch"></switch>
        <button class="remove" onclick="remove($idx)">删除</button>
    </div>
    <div class="item">
        <text class="todo">9点开始开发工作</text>
        <switch showtext="true" checked="false"
                texton="完成" textoff="待办"
                class="switch"></switch>
        <button class="remove" onclick="remove($idx)">删除</button>
    </div>
    <div class="item">
        <text class="todo">18点</text>
        <switch showtext="true" checked="false"
                texton="完成" textoff="待办"
                class="switch"></switch>
        <button class="remove" onclick="remove($idx)">删除</button>
    </div>
    <div class="info">
        <text class="info-text">您还有</text>
        <text class="info-num">2</text>
        <text class="info-text">件事情待办,加油!</text>
    </div>
    <div class="add-todo">
        <input class="plan-input" type="text"></input>
        <button class="plan-btn" onclick="addTodo">添加待办</button>
    </div>
</div>

 2.页面样式设计注意事项

 

.container {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-bottom: 100px;
}
.title {
    font-size: 25px;
    margin-top: 20px;
    margin-bottom: 20px;
    color: #000000;
    opacity: 0.9;
        font-size: 28px;
}
.item{
    width: 325px;
    padding: 10px 0;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    border-bottom: 1px solid #eee;
}
.todo{
    color: #000;
    width: 180px;
    font-size: 18px;
}
.switch{
    font-size: 12px;
    texton-color: green;
    textoff-color:red;
    text-padding: 5px;
    width: 100px;
    height: 24px;
    allow-scale: false;
}
.remove {
    font-size: 12px;
    margin-left: 10px;
    width: 50px;
    height: 22px;
    color: #fff;
    background-color: red;
}
.info{
    width: 100%;
    margin-top: 10px;
    justify-content: center;
}
.info-text {
    font-size: 18px;
    color: #AD7A1B;
}
.info-num{
    color: orangered;
    margin-left: 10px;
    margin-right: 10px;
}
.add-todo {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    background-color: #ddd;
}

.plan-input {
    width: 240px;
    height: 40px;
    background-color: #fff;
}
.plan-btn {
    width: 90px;
    height: 35px;
    font-size: 15px;
}

 3.数据渲染与事件绑定

export default [
    {
        info: '给老王打个电话',
        status: true
    },
    {
        info: '输出工作计划',
        status: false
    },
    {
        info: '和小王对接需求',
        status: true
    },
    {
        info: '整理客户资料',
        status: false
    },
    {
        info: '和朋友一起聚餐',
        status: false
    }
]
import todoList from "../../common/datas/todoList.js"

 二、页面样式布局 

1.设计规则 

  1. JS UI 框架页面样式,系统基于 flex 弹性布局进行设置,默认就是 flex 弹性布局,需要注意,弹性布局会自动的拉升和压缩内部元素模块宽度、高度。

  2. JS UI框架中手机和智慧屏中的 px 指逻辑像素,px 是根据实际屏幕宽度物理像素进行缩放计算的。例如当width 设为 100px 时,在宽度为1440物理像素的屏幕上,实际显示的宽度为200物理像素。

  3. 需要注意的地方有:

    • 在 TV 上有一个黑色的背景,需要针对性的调整对应的 CSS 样式,颜色需要重点处理反转。
    • 穿戴设备是一个圆形的表盘,需要针对圆形容器特征专门设计对应的样式
  4. 媒体查询

    • 针对设备和应用的属性信息,可以设计出相匹配的布局样式。

    • 当屏幕发生动态改变时(比如分屏、横竖屏切换),应用页面布局同步更新。

2.Todolist页面多端适配实现

@media screen and (device-type: phone)  {
    .title {
        font-size: 28px;
    }
}

@media screen and (device-type: tv) {
    .container {
        background-image: url("../../common/images/Wallpaper.png");
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
    .title {
        font-size: 40px;
        color: #FFFFFF;
    }
    .item{
        width: 600px;
        padding-top: 10px;
        padding-bottom: 10px;
        border-bottom: 1px solid #666;
    }
    .todo{
        color: #fff;
        width: 400px;
        font-size: 21px;
    }
    .info-text {
        font-size: 21px;
    }
    .add-todo {
        justify-content: center;
        background-color: #333;
    }
    .plan-input {
        width: 320px;
        margin-right: 30px;
    }
    .plan-btn {
        width: 120px;
        height: 40px;
        background-color: #007cba;
    }
}

@media screen and (device-type: wearable) {
    .title {
        font-size: 16px;
        margin-top: 15px;
        margin-bottom: 15px;
        color: #FFFFFF;
    }
    .item{
        width: 180px;
        padding: 5px 0;
        border-bottom: 1px solid #333;
    }
    .todo{
        color: #fff;
        width: 100px;
        font-size: 10px;
    }
    .switch{
        font-size: 8px;
        text-padding: 5px;
        width: 50px;
        height: 24px;
    }
    .remove {
        font-size: 8px;
        margin-left: 2px;
        width: 30px;
        height: 20px;
        background-color: #fff;
        text-color: red;
    }
    .info-text {
        font-size: 10px;
    }
    .add-todo {
        height: 40px;
        padding-top: 5px;
        align-items: flex-start;
        justify-content: center;
        background-color: #333;
    }
    .plan-input {
        width:80px;
        height: 20px;
        margin-right: 4px;
    }
    .plan-btn {
        width: 40px;
        height: 20px;
        font-size: 7px;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值