HarmonyOS鸿蒙最全鸿蒙OS应用开发之——页面布局DirectionalLayout(1),2024年最新来一份全面的面试宝典练练手

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!


img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

<solid

ohos:color=“#00FFFD”/>

3.2 水平排列

效果图

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

代码

布局文件

<?xml version="1.0" encoding="utf-8"?>

<DirectionalLayout

xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:width=“match_parent”

ohos:height=“match_content”

ohos:orientation=“horizontal”>

<Button

ohos:width=“33vp”

ohos:height=“20vp”

ohos:left_margin=“13vp”

ohos:background_element=“$graphic:color_cyan_element”

ohos:text=“Button 1”/>

<Button

ohos:width=“33vp”

ohos:height=“20vp”

ohos:left_margin=“13vp”

ohos:background_element=“$graphic:color_cyan_element”

ohos:text=“Button 2”/>

<Button

ohos:width=“33vp”

ohos:height=“20vp”

ohos:left_margin=“13vp”

ohos:background_element=“$graphic:color_cyan_element”

ohos:text=“Button 3”/>

color_cyan_element.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:shape=“rectangle”>

<solid

ohos:color=“#00FFFD”/>

四 DirectionalLayout对齐方式


4.1 对齐方式属性表

| 参数 | 作用 | 可搭配排列方式 |

| :-: | :-: | :-: |

| left | 左对齐 | 垂直排列 |

| top | 顶部对齐 | 水平排列 |

| right | 右对齐 | 垂直排列 |

| bottom | 底部对齐 | 水平排列 |

| horizontal_center | 水平方向居中 | 垂直排列 |

| vertical_center | 垂直方向居中 | 水平排列 |

| center | 垂直与水平方向都居中 | 水平/垂直排列 |

4.2 实例

效果图

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

布局文件示例代码

<?xml version="1.0" encoding="utf-8"?>

<DirectionalLayout

xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:width=“match_parent”

ohos:height=“60vp”>

<Button

ohos:width=“50vp”

ohos:height=“20vp”

ohos:background_element=“$graphic:color_cyan_element”

ohos:layout_alignment=“left”

ohos:text=“Button 1”/>

<Button

ohos:width=“50vp”

ohos:height=“20vp”

ohos:background_element=“$graphic:color_cyan_element”

ohos:layout_alignment=“horizontal_center”

ohos:text=“Button 2”/>

<Button

ohos:width=“50vp”

ohos:height=“20vp”

ohos:background_element=“$graphic:color_cyan_element”

ohos:layout_alignment=“right”

ohos:text=“Button 3”/>

color_cyan_element.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:shape=“rectangle”>

<solid

ohos:color=“#00FFFD”/>

五 权重


5.1 说明

  • 权重(weight)就是按比例来分配组件占用父组件的大小

  • 父布局可分配宽度=父布局宽度-所有子组件width之和;

  • 组件宽度=组件weight/所有组件weight之和*父布局可分配宽度;

5.2 实例

效果图

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

布局文件

<?xml version="1.0" encoding="utf-8"?>

<DirectionalLayout

xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:width=“match_parent”

ohos:height=“match_content”

ohos:orientation=“horizontal”>

<Button

ohos:width=“0vp”

ohos:height=“20vp”

ohos:weight=“1”

ohos:background_element=“$graphic:color_cyan_element”

ohos:text=“Button 1”/>

<Button

ohos:width=“0vp”

ohos:height=“20vp”

ohos:weight=“1”

ohos:background_element=“$graphic:color_gray_element”

ohos:text=“Button 2”/>

<Button

ohos:width=“0vp”

ohos:height=“20vp”

ohos:weight=“1”

ohos:background_element=“$graphic:color_cyan_element”

ohos:text=“Button 3”/>

color_cyan_element.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:shape=“rectangle”>

<solid

ohos:color=“#00FFFD”/>

color_gray_element.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:shape=“rectangle”>

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!


img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

ttps://img-blog.csdnimg.cn/direct/743b668910224b259a5ffe804fa6d0db.png)
[外链图片转存中…(img-vtqmWxje-1715302396448)]
[外链图片转存中…(img-v7lr8Vlo-1715302396448)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

  • 29
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 Spring Boot 实战项目,用于管理用户信息: 1. 创建一个基础的 Spring Boot 项目,引入以下依赖: ```xml <!-- Spring Boot Web 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Boot JPA 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- H2 数据库依赖 --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> ``` 2. 创建一个实体类 User,包含 id、name、age 三个属性: ```java @Entity @Table(name = "user") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private Integer age; // 省略 getter 和 setter 方法 } ``` 3. 创建一个 UserRepository 接口,继承 JpaRepository,用于操作用户数据: ```java @Repository public interface UserRepository extends JpaRepository<User, Long> { } ``` 4. 创建一个 UserController 类,用于处理用户信息的增删改查: ```java @RestController @RequestMapping("/users") public class UserController { @Autowired private UserRepository userRepository; @GetMapping("") public List<User> list() { return userRepository.findAll(); } @PostMapping("") public User create(@RequestBody User user) { return userRepository.save(user); } @GetMapping("/{id}") public User get(@PathVariable Long id) { return userRepository.findById(id).orElse(null); } @PutMapping("/{id}") public User update(@PathVariable Long id, @RequestBody User user) { user.setId(id); return userRepository.save(user); } @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { userRepository.deleteById(id); } } ``` 5. 启动项目,访问 http://localhost:8080/users 即可查看用户列表,使用 POST、PUT、DELETE 方法操作用户信息。 以上就是一个简单的 Spring Boot 实战项目,可以通过这个项目练习 Spring Boot 的基本使用和 RESTful API 的实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值