HarmonyOS 初体验

HarmonyOS 入门

线性布局

线性布局(LinearLayout)是开发中最常用的布局,通过线性容器RowColumn构建。线性布局是其他布局的基础,其子元素在线性方向上(水平方向和垂直方向)依次排列。线性布局的排列方向由所选容器组件决定,Column容器内子元素按照垂直方向排列,Row容器内子元素按照水平方向排列。根据不同的排列方向,开发者可选择使用Row或Column容器创建线性布局。

1.垂直布局

Column 从上到下布局

@Entry
@Component
struct OnePage {
  build() {
   //  布局  线性布局
   //  column从上往下布局
   Column(){
     // Text文本组件
     Text('列.......').backgroundColor("green")
     Text('元素垂直向下').backgroundColor("red")
     Text('元素垂直向下').backgroundColor("blue")
     Text('元素垂直向下').backgroundColor("black")
   }
   .height('100%')
   .width('100%')
  }
}
2.水平布局

Row 从左往右布局

@Entry
@Component
struct RowPage {
  @State message: string = 'Hello World';
  build() {
  // 行的布局   水平方向从左往右
  Row(){
    Text("行布局").backgroundColor("red")
    Text("行布局").backgroundColor("#999")
    Text("行布局").backgroundColor("#f70")
    Text("行布局").backgroundColor("green")
    Text("行布局").backgroundColor("blue")
    Text("行布局").backgroundColor("#f70")
    Text("行布局").backgroundColor("green")
    Text("行布局").backgroundColor("blue")
    Text("行布局").backgroundColor("#f70")
    Text("行布局").backgroundColor("green")
    Text("行布局").backgroundColor("blue")
   }
  }
}

组件

1.文本显示
Text("hello word!")
  .fontSize(30)//字体大小      单位vp
  .fontColor(Color.Orange)//字体颜色
  .textAlign(TextAlign.Start)//水平对其方式   不生效位置不对
  .decoration({
    //写多个属性
    //类型:下划线,删除线,上划线
    type:TextDecorationType.Underline,
    color:"blue",
    style:TextDecorationStyle.DOTTED  //线的样式
  })//装饰:下划线,删除线,上划线
2文本输入
//文本输入框
// {placeholder输入的提示,text:默认值
TextInput({placeholder:"请输入帐号",text:"admin"})//默认样式,有圆角的输入框

TextInput({placeholder:"请输入密码"})
  .type(InputType.Password)//输入框类型:密码
  .borderRadius(10)//圆角
  .backgroundColor("green")
3.按钮
//按钮
Button("按钮").width(100)
//type:ButtonType.Circle  按钮的形状
// stateEffect:false    按钮下压的状态
Button("圆形按钮",{type:ButtonType.Circle,stateEffect:false})
  .height(120)
Button("胶囊按钮",{type:ButtonType.Capsule,stateEffect:false})
Button("普通按钮",{type:ButtonType.Normal,stateEffect:false})
4.图片
@Entry
@Component
struct ImagePage {
  @State message: string = 'Hello World';

  build() {
  Column(){
  //   $r('app.media.startIcon')     resources>base>media   不用写后缀
  Image($r('app.media.startIcon'))
    .width(100)
    // resources>rawfile    需要写完整的图片名称
    Image($rawfile("006OuROzly1hhh19bwh8nj34802tc4qw.jpg"))
      .width(400)
      .renderMode(ImageRenderMode.Original)//渲染颜色
    //加载网络图片需要申请网络权限
  Image("https://img30.360buyimg.com/pop/s1180x940_jfs/t1/80849/38/24536/56064/669e1cf8Fdfccdaa0/02464ee6675fda44.jpg.webp")
  Image($rawfile("user.png"))
    .width(120)

    //图片插值  抗锯齿
    .interpolation(ImageInterpolation.High)


  }
  .height("100%")
  .width("100%")
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值