鸿蒙OS应用开发之——Java UI框架-组件与布局开发,2024年最新kotlin从入门到进阶实战pdf

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

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

因此收集整理了一份《2024年最新HarmonyOS鸿蒙全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img

img
img
htt

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

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

如果你需要这些资料,可以添加V获取:vip204888 (备注鸿蒙)
img

正文

DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT);

layoutConfig.alignment = LayoutAlignment.HORIZONTAL_CENTER;

text.setLayoutConfig(layoutConfig);

// 将Text添加到布局中

directionalLayout.addComponent(text);

// 类似的添加一个Button

Button button = new Button(getContext());

layoutConfig.setMargins(0, 50, 0, 0);

button.setLayoutConfig(layoutConfig);

button.setText(“My name is Button.”);

button.setTextSize(50);

ShapeElement background = new ShapeElement();

background.setRgbColor(new RgbColor(0, 125, 255));

background.setCornerRadius(25);

button.setBackground(background);

button.setPadding(10, 10, 10, 10);

button.setClickedListener(new Component.ClickedListener() {

@Override

// 在组件中增加对点击事件的检测

public void onClick(Component Component) {

// 此处添加按钮被点击需要执行的操作

}

});

directionalLayout.addComponent(button);

// 将布局作为根布局添加到视图树中

super.setUIContent(directionalLayout);

}

}

运行效果

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

4.2 XML创建布局


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

<DirectionalLayout

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

ohos:width=“match_parent”

ohos:height=“match_parent”

ohos:orientation=“vertical”

ohos:padding=“32”>

<Text

ohos:id=“$+id:text”

ohos:width=“match_content”

ohos:height=“match_content”

ohos:layout_alignment=“horizontal_center”

ohos:text=“My name is Text.”

ohos:text_size=“25vp”/>

<Button

ohos:id=“$+id:button”

ohos:margin=“50”

ohos:width=“match_content”

ohos:height=“match_content”

ohos:layout_alignment=“horizontal_center”

ohos:text=“My name is Button.”

ohos:text_size=“50”/>

加载XML布局

package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;

import ohos.aafwk.content.Intent;

import ohos.agp.colors.RgbColor;

import ohos.agp.components.*;

import ohos.agp.components.element.ShapeElement;

public class ExampleAbilitySlice extends AbilitySlice {

@Override

public void onStart(Intent intent) {

super.onStart(intent);

// 加载XML布局作为根布局

super.setUIContent(ResourceTable.Layout_first_layout);

Button button = (Button) findComponentById(ResourceTable.Id_button);

if (button != null) {

// 设置组件的属性

ShapeElement background = new ShapeElement();

background.setRgbColor(new RgbColor(0, 125, 255));

background.setCornerRadius(25);

button.setBackground(background);

button.setClickedListener(new Component.ClickedListener() {

@Override

// 在组件中增加对点击事件的检测

public void onClick(Component Component) {

// 此处添加按钮被点击需要执行的操作

}

});

}

}

}

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注鸿蒙)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注鸿蒙)
[外链图片转存中…(img-ArIoCtBP-1713218907804)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值