-
Notifications
You must be signed in to change notification settings - Fork 207
ViewDemo.lua
xu.jingyu edited this page Dec 24, 2019
·
6 revisions
copy下面代码,运行试试
-----------------------
local W = window:width()
local lightGray = Color(230,230,230,1)
baseView1 = View():width(W):height(80):marginTop(100)
baseView1:bgColor(lightGray)
window:addView(baseView1)
local iv = ImageView():width(80):height(80):bgColor(Color(130,130,130,1))
iv:addCornerMask(40, lightGray, RectCorner.ALL_CORNERS)
iv:image('http://img5.imgtn.bdimg.com/it/u=3604858831,3357525860&fm=27&gp=0.jpg')
iv:setGravity(Gravity.CENTER_VERTICAL):marginLeft(10)
baseView1:addView(iv)
distanceLabel = Label():bgColor(Color(131, 175, 155, 1))
distanceLabel:text("5.6km")
distanceLabel:setGravity(MBit:bor(Gravity.CENTER_VERTICAL,Gravity.RIGHT)):marginRight(10)
baseView1:addView(distanceLabel)
-----------------------
label3 = Label():marginTop(270)
label3:bgColor(Color(230, 230, 230, 1))
label3:text("点击下方的 绿色view")
window:addView(label3)
-- 布局时用subView内容自适应
baseView3 = View():width(MeasurementType.WRAP_CONTENT):height(MeasurementType.WRAP_CONTENT):marginTop(300)
baseView3:bgColor(Color(130, 130, 130, 1))
window:addView(baseView3)
count = 0
view = View():marginTop(10):marginLeft(20):marginRight(20):marginBottom(20):width(150):height(80)
view:bgColor(Color(131, 175, 155, 1))
view:openRipple(true) -- 点击时的波纹效果
baseView3:addView(view)
view:onClick(function ()
count = count + 1
local str = string.format("click次数: %d", count)
label_click:text(str)
end)
label_click = Label():marginTop(300):marginLeft(200)
label_click:fontSize(11)
label_click:bgColor(Color(230, 230, 230, 1))
window:addView(label_click)
label_touch = Label():marginTop(330):marginLeft(200)
label_touch:fontSize(11)
label_touch:bgColor(Color(230, 230, 230, 1))
window:addView(label_touch)
-----------------------
-- MeasurementType.WRAP_CONTENT: 布局时用subView内容自适应
linearLayout = LinearLayout():width(MeasurementType.WRAP_CONTENT):height(MeasurementType.WRAP_CONTENT):marginTop(450)
linearLayout:bgColor(Color(130, 130, 130, 1))
window:addView(linearLayout)
label1 = Label()
label1:bgColor(Color(230, 230, 230, 1))
label1:text("第1个 label")
linearLayout:addView(label1)
label2 = Label():marginLeft(10):marginTop(10):marginBottom(10):marginRight(20)
label2:bgColor(Color(230, 230, 230, 1))
label2:text("第2个 label")
linearLayout:addView(label2)