以下是一个基本的 AndLua 多按钮布局代码示例,它包括 5 个按钮:

local widget = require("widget")

-- 创建背景
local background = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight)
background:setFillColor(1, 1, 1)

-- 创建按钮
local button1 = widget.newButton({
    label = 'Button 1',
    x = display.contentCenterX,
    y = display.contentHeight * 0.2,
    width = 200,
    height = 60,
    shape = 'roundedRect',
    cornerRadius = 10,
    fillColor = { default={1,0,0,1}, over={1,0.5,0.5,1} },
    onPress = function(event)
        print('Button 1 pressed')
    end
})

local button2 = widget.newButton({
    label = 'Button 2',
    x = display.contentCenterX,
    y = display.contentHeight * 0.35,
    width = 200,
    height = 60,
    shape = 'roundedRect',
    cornerRadius = 10,
    fillColor = { default={0,1,0,1}, over={0.5,1,0.5,1} },
    onPress = function(event)
        print('Button 2 pressed')
    end
})

local button3 = widget.newButton({
    label = 'Button 3',
    x = display.contentCenterX,
    y = display.contentHeight * 0.5,
    width = 200,
    height = 60,
    shape = 'roundedRect',
    cornerRadius = 10,
    fillColor = { default={0,0,1,1}, over={0.5,0.5,1,1} },
    onPress = function(event)
        print('Button 3 pressed')
    end
})

local button4 = widget.newButton({
    label = 'Button 4',
    x = display.contentCenterX,
    y = display.contentHeight * 0.65,
    width = 200,
    height = 60,
    shape = 'roundedRect',
    cornerRadius = 10,
    fillColor = { default={1,1,0,1}, over={1,1,0.5,1} },
    onPress = function(event)
        print('Button 4 pressed')
    end
})

local button5 = widget.newButton({
    label = 'Button 5',
    x = display.contentCenterX,
    y = display.contentHeight * 0.8,
    width = 200,
    height = 60,
    shape = 'roundedRect',
    cornerRadius = 10,
    fillColor = { default={1,0,1,1}, over={1,0.5,1,1} },
    onPress = function(event)
        print('Button 5 pressed')
    end
})

这个例子使用了 widget 库来创建按钮,每个按钮都有一个唯一的标签和颜色。可以根据需要更改按钮的位置,颜色和其他属性。

AndLua 多按钮布局示例:创建 5 个按钮

原文地址: https://www.cveoy.top/t/topic/nuSp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录