效果如图所示: 
很多朋友可能刚接触harmony,我给大家带来一个有趣的ui页面,如封面所示。代码如下图所示。可以参考。如想直接使用注意 1.插入的图片,你的media中没有,自己找图片复制粘,位置在 entry-src-main-resources-base-media
1.滚动主要依靠
List(){
ListItem(){}
//这里还可以扩充,ListItem(){}
}
.scrollBar(BarState.Off)2.想让屏幕全部变黑不要有上下两边留白,加上这个
.expendSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])3.想要合适的间距,多用 .padding 内边距 和 .margin 外边距 ,举个例子
.padding({left:10,bottom: 10,right:10,top:10}).margin({ left:10,bottom: 10,right:10,top:10 })这两个也等同于
.padding({10}).padding({10})
4.如何在两个东西之间插入文字
.layoutWeight(1)//把其他组件排除掉占剩下的组件就是这个能把其他两个组件排开,自己占剩下的位置!!!
5.要有大局观,先做整体,在优化局部,多尝试,不要害怕报错,慢慢改。
@Entry
@Component
struct Index {
build() {
Column() {
Text("My love")
.fontSize(24)
.fontColor(Color.White)
.width('100%')
.fontWeight(800)
.margin({ bottom: 10 })
List() {
ListItem(){
Row(){
//图
Image($r('app.media.young'))
.width(80)
.border({radius:20})
.margin({right:10})
Column(){
Text("Young")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%")
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.closer'))
.width(80)
.height(80)
.border({radius:20})
.margin({right:10})
//文字
Column(){
Text("Closer")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%") //可用于左对齐
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.paris'))
.width(80)
.border({radius:20})
.margin({right:10})
Column(){
Text("Paris")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%")
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.young'))
.width(80)
.border({radius:20})
.margin({right:10})
Column(){
Text("Young")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%")
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.closer'))
.width(80)
.height(80)
.border({radius:20})
.margin({right:10})
//文字
Column(){
Text("Closer")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%") //可用于左对齐
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.paris'))
.width(80)
.border({radius:20})
.margin({right:10})
Column(){
Text("Paris")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%")
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.young'))
.width(80)
.border({radius:20})
.margin({right:10})
Column(){
Text("Young")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%")
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.closer'))
.width(80)
.height(80)
.border({radius:20})
.margin({right:10})
//文字
Column(){
Text("Closer")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%") //可用于左对齐
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
ListItem(){
Row(){
//图
Image($r('app.media.paris'))
.width(80)
.border({radius:20})
.margin({right:10})
Column(){
Text("Paris")
.fontColor('#F3F3F3')
.width('100%')
.fontSize(20)
.fontWeight(700) //加粗
.margin(({bottom:10}))
Row(){
Text("ViP")
.fontColor("#FB9093")
.fontWeight(600)
.border({width:2,color:'#FB9093',style:BorderStyle.Solid,radius:10})
.padding({left:3,right:3,top:3,bottom:3})
.margin({right:9})
Text("The Chainsmokers")
.fontColor('#FAFAFA')
.fontWeight(600)
}
.width("100%")
}
.layoutWeight(1)//把其他组件排除掉占剩下的组件
Image($r("app.media.yuan4"))
.width(26)
}
.width("100%")
.height(80)
.backgroundColor(Color.Black)
.margin({bottom:10})
}
}
.scrollBar(BarState.Off)
/*可滚动组件:
List(){
ListItem(){}
}
.scrollBar(BarState.Off)
*/
}
.width('100%')
.height("100%")
.backgroundColor(Color.Black)
.padding({left:10,right:10})
.expandSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM]) //扩充组件安全区域
}
}




































苏公安网备 32011402010933号