-
Notifications
You must be signed in to change notification settings - Fork 207
LinearLayoutDemo.lua
xu_whale edited this page Dec 6, 2019
·
4 revisions
copy下面代码,运行试试
local screen_w = window:width()
local screen_h = window:height()
local stateBar = window:stateBarHeight()
local baseView = LinearLayout(LinearType.VERTICAL)
baseView:width(screen_w):height(screen_h)
window:addView(baseView)
local linear1 = LinearLayout(LinearType.HORIZONTAL)
linear1:width(screen_w):height(100):marginTop(stateBar + 10)
local t11 = Label()
t11:text('1-1')
t11:width(100):height(100)
t11:bgColor(Color(255,0,0,1))
local t12 = Label()
t12:text('1-2')
t12:width(100):height(100)
t12:bgColor(Color(0,255,0,1))
local t13 = Label()
t13:text('1-3')
t13:width(100):height(100)
t13:bgColor(Color(0,0,255,1))
linear1:addView(t11):addView(t12):addView(t13)
baseView:addView(linear1)
local linear2 = LinearLayout()
linear2:width(screen_w):height(100):marginTop(20)
local t21 = Label()
t21:text('2-1')
t21:width(100):height(100)
t21:bgColor(Color(255,0,0,1))
local t22 = Label()
t22:text('2-2')
t22:width(100):height(100)
t22:bgColor(Color(0,255,0,1))
t22:marginLeft(10):marginRight(10)
local t23 = Label()
t23:text('2-3')
t23:width(100):height(100)
t23:bgColor(Color(0,0,255,1))
linear2:addView(t21):addView(t22):addView(t23)
baseView:addView(linear2)
local linear3 = LinearLayout()
linear3:width(200):height(100):marginTop(20)
local t31 = Label()
t31:text('3-1')
t31:height(100)
t31:bgColor(Color(255,0,0,1))
local t32 = Label()
t32:text('3-2')
t32:width(150):height(30)
t32:bgColor(Color(0,255,0,1))
t32:marginLeft(10):marginRight(10):marginTop(10)
local t33 = ImageView()
t33:image('http://s.momocdn.com/w/u/others/2019/01/24/1548319052212-wallhaven-619292.jpg')
t33:width(128):height(72)
linear3:addView(t31):addView(t32):addView(t33)
linear3:bgColor(Color(0,0,255,0.3))
baseView:addView(linear3)
local linear4 = LinearLayout()
linear4:marginTop(20)
linear4:setWrapContent(true) --大小按照内容自适应
local t41 = Label()
t41:text('4-1')
t41:bgColor(Color(255,0,0,1))
t41:setGravity(Gravity.CENTER_VERTICAL)
local t42 = Label()
t42:text('4-2')
t42:width(100):height(40)
t42:bgColor(Color(0,255,0,1))
t42:marginLeft(10):marginRight(10):marginTop(10)
local t44 = ImageView()
t44:image('http://s.momocdn.com/w/u/others/2019/01/24/1548319052212-wallhaven-619292.jpg')
t44:width(128):height(72)
linear4:addView(t41):addView(t42):addView(t44)
linear4:bgColor(Color(0,0,255,0.4))
baseView:addView(linear4)
local linear5 = LinearLayout()
linear5:bgColor(Color(0,0,255,0.4)):marginTop(20)
linear5:setWrapContent(true)
local t51 = Label():setWrapContent(true):bgColor(Color(255,0,0,1))
t51:text('low priority: xxxxxxxxx end|')
local t52 = Label():setWrapContent(true):bgColor(Color(0,255,0,1)):priority(2)
t52:text('high priority: xxxxx end|')
local t53 = Label():setWrapContent(true):bgColor(Color(0,0,255,1)):priority(1)
t53:text('medium priority: xxx end|')
linear5:addView(t51):addView(t52):addView(t53)
baseView:addView(linear5)