B2B网络软件

标题: AIWROK软件苹果水平容器[Horizontal]小实例 [打印本页]

作者: YYPOST群发软件    时间: 3 小时前
标题: AIWROK软件苹果水平容器[Horizontal]小实例
AIWROK软件苹果水平容器[Horizontal]小实例
AIWROK软件苹果水平容器[Horizontal]小实例 B2B网络软件

AIWROK软件苹果水平容器[Horizontal]小实例 B2B网络软件

AIWROK软件苹果水平容器[Horizontal]小实例 B2B网络软件

  1. // 🎨UI-水平容器[Horizontal]全新系统化示例
  2. // 全面展示Horizontal容器的所有功能和方法
  3. // 🍎交流QQ群711841924群一,苹果内测群,528816639

  4. printl("=== Horizontal水平容器全新系统化示例启动 ===");

  5. var tab = new TabView();

  6. tab.setTitles(["基础", "对齐", "动态", "嵌套", "实战"]);

  7. tab.show(function() {
  8.     printl("TabView界面加载完成");
  9.    
  10.     // ====================== 第一页:基础布局 ======================
  11.     var basicPage = new Vertical();
  12.     basicPage.setSpacing(8);
  13.     basicPage.setBackgroundColor(248, 250, 252);
  14.    
  15.     var basicHeader = createSectionHeader("基础布局演示", 70, 130, 180);
  16.     basicPage.addView(basicHeader);
  17.    
  18.     var basicDesc = new Label();
  19.     basicDesc.setText("展示Horizontal容器的基本功能:addView添加控件、setSpacing设置间距、setBackgroundColor设置背景色");
  20.     basicDesc.setTextColor(100, 100, 100);
  21.     basicDesc.setFontSize(13);
  22.     basicDesc.setTextAlignment("center");
  23.     basicPage.addView(basicDesc);
  24.    
  25.     // 演示1:基本按钮组
  26.     var demo1Section = createSubSection("基本按钮组");
  27.     basicPage.addView(demo1Section);
  28.    
  29.     var buttonGroup = new Horizontal();
  30.     buttonGroup.setSpacing(12);
  31.     buttonGroup.setAlignment("center");
  32.     buttonGroup.setBackgroundColor(245, 245, 245);
  33.    
  34.     var btn1 = createColorButton("首页", 52, 152, 219);
  35.     var btn2 = createColorButton("分类", 46, 204, 113);
  36.     var btn3 = createColorButton("购物车", 241, 196, 15);
  37.     var btn4 = createColorButton("我的", 155, 89, 182);
  38.    
  39.     buttonGroup.addView(btn1);
  40.     buttonGroup.addView(btn2);
  41.     buttonGroup.addView(btn3);
  42.     buttonGroup.addView(btn4);
  43.    
  44.     basicPage.addView(buttonGroup);
  45.    
  46.     // 演示2:不同间距对比 - 重新设计,使用彩色方块直观展示
  47.     var demo2Section = createSubSection("间距对比演示");
  48.     basicPage.addView(demo2Section);
  49.    
  50.     var spacingContainer = new Vertical();
  51.     spacingContainer.setSpacing(15);
  52.     spacingContainer.setBackgroundColor(255, 255, 255);
  53.    
  54.     // 小间距演示
  55.     var smallRow = new Vertical();
  56.     smallRow.setSpacing(5);
  57.    
  58.     var smallLabel = new Label();
  59.     smallLabel.setText("setSpacing(5) - 小间距");
  60.     smallLabel.setTextColor(80, 80, 80);
  61.     smallLabel.setFontSize(12);
  62.     smallRow.addView(smallLabel);
  63.    
  64.     var smallSpacing = new Horizontal();
  65.     smallSpacing.setSpacing(5);
  66.     smallSpacing.setAlignment("center");
  67.     smallSpacing.setBackgroundColor(240, 240, 240);
  68.    
  69.     for (var s1 = 1; s1 <= 4; s1++) {
  70.         var box1 = new Label();
  71.         box1.setText("");
  72.         box1.setBackgroundColor(52, 152, 219);
  73.         box1.setWidth(40);
  74.         box1.setHeight(40);
  75.         smallSpacing.addView(box1);
  76.     }
  77.     smallRow.addView(smallSpacing);
  78.    
  79.     // 中间距演示
  80.     var mediumRow = new Vertical();
  81.     mediumRow.setSpacing(5);
  82.    
  83.     var mediumLabel = new Label();
  84.     mediumLabel.setText("setSpacing(15) - 中间距");
  85.     mediumLabel.setTextColor(80, 80, 80);
  86.     mediumLabel.setFontSize(12);
  87.     mediumRow.addView(mediumLabel);
  88.    
  89.     var mediumSpacing = new Horizontal();
  90.     mediumSpacing.setSpacing(15);
  91.     mediumSpacing.setAlignment("center");
  92.     mediumSpacing.setBackgroundColor(240, 240, 240);
  93.    
  94.     for (var s2 = 1; s2 <= 4; s2++) {
  95.         var box2 = new Label();
  96.         box2.setText("");
  97.         box2.setBackgroundColor(46, 204, 113);
  98.         box2.setWidth(40);
  99.         box2.setHeight(40);
  100.         mediumSpacing.addView(box2);
  101.     }
  102.     mediumRow.addView(mediumSpacing);
  103.    
  104.     // 大间距演示
  105.     var largeRow = new Vertical();
  106.     largeRow.setSpacing(5);
  107.    
  108.     var largeLabel = new Label();
  109.     largeLabel.setText("setSpacing(25) - 大间距");
  110.     largeLabel.setTextColor(80, 80, 80);
  111.     largeLabel.setFontSize(12);
  112.     largeRow.addView(largeLabel);
  113.    
  114.     var largeSpacing = new Horizontal();
  115.     largeSpacing.setSpacing(25);
  116.     largeSpacing.setAlignment("center");
  117.     largeSpacing.setBackgroundColor(240, 240, 240);
  118.    
  119.     for (var s3 = 1; s3 <= 4; s3++) {
  120.         var box3 = new Label();
  121.         box3.setText("");
  122.         box3.setBackgroundColor(155, 89, 182);
  123.         box3.setWidth(40);
  124.         box3.setHeight(40);
  125.         largeSpacing.addView(box3);
  126.     }
  127.     largeRow.addView(largeSpacing);
  128.    
  129.     spacingContainer.addView(smallRow);
  130.     spacingContainer.addView(mediumRow);
  131.     spacingContainer.addView(largeRow);
  132.    
  133.     basicPage.addView(spacingContainer);
  134.    
  135.     // 演示3:背景色设置 - 重新设计,展示完整背景效果
  136.     var demo3Section = createSubSection("背景色设置");
  137.     basicPage.addView(demo3Section);
  138.    
  139.     var bgContainer = new Vertical();
  140.     bgContainer.setSpacing(12);
  141.    
  142.     // 红色背景
  143.     var bg1 = new Horizontal();
  144.     bg1.setSpacing(10);
  145.     bg1.setAlignment("center");
  146.     bg1.setBackgroundColor(231, 76, 60);
  147.    
  148.     var bg1Label = new Label();
  149.     bg1Label.setText("setBackgroundColor(231, 76, 60)");
  150.     bg1Label.setTextColor(255, 255, 255);
  151.     bg1Label.setFontSize(14);
  152.     bg1Label.setTextAlignment("center");
  153.     bg1Label.setHeight(40);
  154.     bg1.addView(bg1Label);
  155.    
  156.     // 绿色背景
  157.     var bg2 = new Horizontal();
  158.     bg2.setSpacing(10);
  159.     bg2.setAlignment("center");
  160.     bg2.setBackgroundColor(46, 204, 113);
  161.    
  162.     var bg2Label = new Label();
  163.     bg2Label.setText("setBackgroundColor(46, 204, 113)");
  164.     bg2Label.setTextColor(255, 255, 255);
  165.     bg2Label.setFontSize(14);
  166.     bg2Label.setTextAlignment("center");
  167.     bg2Label.setHeight(40);
  168.     bg2.addView(bg2Label);
  169.    
  170.     // 蓝色背景
  171.     var bg3 = new Horizontal();
  172.     bg3.setSpacing(10);
  173.     bg3.setAlignment("center");
  174.     bg3.setBackgroundColor(52, 152, 219);
  175.    
  176.     var bg3Label = new Label();
  177.     bg3Label.setText("setBackgroundColor(52, 152, 219)");
  178.     bg3Label.setTextColor(255, 255, 255);
  179.     bg3Label.setFontSize(14);
  180.     bg3Label.setTextAlignment("center");
  181.     bg3Label.setHeight(40);
  182.     bg3.addView(bg3Label);
  183.    
  184.     bgContainer.addView(bg1);
  185.     bgContainer.addView(bg2);
  186.     bgContainer.addView(bg3);
  187.    
  188.     basicPage.addView(bgContainer);
  189.    
  190.     tab.addView(0, basicPage);
  191.    
  192.     // ====================== 第二页:对齐方式 ======================
  193.     var alignPage = new Vertical();
  194.     alignPage.setSpacing(8);
  195.     alignPage.setBackgroundColor(252, 248, 250);
  196.    
  197.     var alignHeader = createSectionHeader("对齐方式演示", 155, 89, 182);
  198.     alignPage.addView(alignHeader);
  199.    
  200.     var alignDesc = new Label();
  201.     alignDesc.setText("展示Horizontal容器的三种对齐方式:left左对齐、center居中对齐、right右对齐");
  202.     alignDesc.setTextColor(100, 100, 100);
  203.     alignDesc.setFontSize(13);
  204.     alignDesc.setTextAlignment("center");
  205.     alignPage.addView(alignDesc);
  206.    
  207.     // 左对齐演示
  208.     var leftSection = createSubSection("左对齐 (left)");
  209.     alignPage.addView(leftSection);
  210.    
  211.     var leftContainer = new Horizontal();
  212.     leftContainer.setSpacing(5);
  213.     leftContainer.setAlignment("left");
  214.    
  215.     var leftBox = new Label();
  216.     leftBox.setText("左对齐内容");
  217.     leftBox.setTextColor(255, 255, 255);
  218.     leftBox.setFontSize(14);
  219.     leftBox.setTextAlignment("center");
  220.     leftBox.setBackgroundColor(100, 100, 100);
  221.     leftBox.setWidth(150);
  222.     leftBox.setHeight(40);
  223.    
  224.     leftContainer.addView(leftBox);
  225.    
  226.     alignPage.addView(leftContainer);
  227.    
  228.     // 居中对齐演示
  229.     var centerSection = createSubSection("居中对齐 (center)");
  230.     alignPage.addView(centerSection);
  231.    
  232.     var centerContainer = new Horizontal();
  233.     centerContainer.setSpacing(5);
  234.     centerContainer.setAlignment("center");
  235.    
  236.     var centerBox = new Label();
  237.     centerBox.setText("居中对齐内容");
  238.     centerBox.setTextColor(255, 255, 255);
  239.     centerBox.setFontSize(14);
  240.     centerBox.setTextAlignment("center");
  241.     centerBox.setBackgroundColor(155, 89, 182);
  242.     centerBox.setWidth(150);
  243.     centerBox.setHeight(40);
  244.    
  245.     centerContainer.addView(centerBox);
  246.    
  247.     alignPage.addView(centerContainer);
  248.    
  249.     // 右对齐演示
  250.     var rightSection = createSubSection("右对齐 (right)");
  251.     alignPage.addView(rightSection);
  252.    
  253.     var rightContainer = new Horizontal();
  254.     rightContainer.setSpacing(5);
  255.     rightContainer.setAlignment("right");
  256.    
  257.     var rightBox = new Label();
  258.     rightBox.setText("右对齐内容");
  259.     rightBox.setTextColor(255, 255, 255);
  260.     rightBox.setFontSize(14);
  261.     rightBox.setTextAlignment("center");
  262.     rightBox.setBackgroundColor(52, 73, 94);
  263.     rightBox.setWidth(150);
  264.     rightBox.setHeight(40);
  265.    
  266.     rightContainer.addView(rightBox);
  267.    
  268.     alignPage.addView(rightContainer);
  269.    
  270.     // 对齐方式对比
  271.     var compareSection = createSubSection("对齐效果对比");
  272.     alignPage.addView(compareSection);
  273.    
  274.     var compareContainer = new Vertical();
  275.     compareContainer.setSpacing(12);
  276.    
  277.     var compareLabel = new Label();
  278.     compareLabel.setText("同一行内容在不同对齐方式下的显示效果:");
  279.     compareLabel.setTextColor(80, 80, 80);
  280.     compareLabel.setFontSize(12);
  281.     compareContainer.addView(compareLabel);
  282.    
  283.     var alignTypes = ["left", "center", "right"];
  284.     var alignNames = ["左对齐", "居中对齐", "右对齐"];
  285.    
  286.     for (var i = 0; i < alignTypes.length; i++) {
  287.         var row = new Horizontal();
  288.         row.setSpacing(10);
  289.         row.setAlignment(alignTypes[i]);
  290.         row.setBackgroundColor(230, 240, 250);
  291.         
  292.         var contentLabel = new Label();
  293.         contentLabel.setText(alignNames[i] + "内容");
  294.         contentLabel.setTextColor(255, 255, 255);
  295.         contentLabel.setFontSize(14);
  296.         contentLabel.setTextAlignment("center");
  297.         contentLabel.setBackgroundColor(52, 152, 219);
  298.         contentLabel.setWidth(150);
  299.         contentLabel.setHeight(35);
  300.         row.addView(contentLabel);
  301.         
  302.         compareContainer.addView(row);
  303.     }
  304.    
  305.     alignPage.addView(compareContainer);
  306.    
  307.     tab.addView(1, alignPage);
  308.    
  309.     // ====================== 第三页:动态管理 ======================
  310.     var dynamicPage = new Vertical();
  311.     dynamicPage.setSpacing(8);
  312.     dynamicPage.setBackgroundColor(250, 252, 248);
  313.    
  314.     var dynamicHeader = createSectionHeader("动态管理演示", 46, 204, 113);
  315.     dynamicPage.addView(dynamicHeader);
  316.    
  317.     var dynamicDesc = new Label();
  318.     dynamicDesc.setText("展示动态添加、移除、清空控件以及获取控件数量的功能");
  319.     dynamicDesc.setTextColor(100, 100, 100);
  320.     dynamicDesc.setFontSize(13);
  321.     dynamicDesc.setTextAlignment("center");
  322.     dynamicPage.addView(dynamicDesc);
  323.    
  324.     // 动态添加演示
  325.     var addSection = createSubSection("动态添加控件");
  326.     dynamicPage.addView(addSection);
  327.    
  328.     var addContainer = new Vertical();
  329.     addContainer.setSpacing(10);
  330.    
  331.     var dynamicHorizontal = new Horizontal();
  332.     dynamicHorizontal.setSpacing(10);
  333.     dynamicHorizontal.setAlignment("center");
  334.     dynamicHorizontal.setBackgroundColor(240, 240, 240);
  335.    
  336.     var addButtonsArray = [];
  337.    
  338.     var addStatus = new Label();
  339.     addStatus.setText("当前控件数量: 0");
  340.     addStatus.setTextColor(46, 204, 113);
  341.     addStatus.setFontSize(14);
  342.     addContainer.addView(addStatus);
  343.    
  344.     var addBtn = new Button();
  345.     addBtn.setText("添加控件");
  346.     addBtn.setColor(46, 204, 113);
  347.     addBtn.setTextColor(255, 255, 255);
  348.     addBtn.setWidth(120);
  349.     addBtn.setHeight(40);
  350.     addBtn.onClick(function() {
  351.         var newBtn = createColorButton("新" + (addButtonsArray.length + 1), 46, 204, 113);
  352.         addButtonsArray.push(newBtn);
  353.         dynamicHorizontal.addView(newBtn);
  354.         addStatus.setText("当前控件数量: " + addButtonsArray.length);
  355.         printl("添加控件,当前数量: " + addButtonsArray.length);
  356.     });
  357.    
  358.     addContainer.addView(dynamicHorizontal);
  359.     addContainer.addView(addBtn);
  360.    
  361.     dynamicPage.addView(addContainer);
  362.    
  363.     // 动态移除演示
  364.     var removeSection = createSubSection("动态移除控件");
  365.     dynamicPage.addView(removeSection);
  366.    
  367.     var removeContainer = new Vertical();
  368.     removeContainer.setSpacing(10);
  369.    
  370.     var removeHorizontal = new Horizontal();
  371.     removeHorizontal.setSpacing(10);
  372.     removeHorizontal.setAlignment("center");
  373.     removeHorizontal.setBackgroundColor(240, 240, 240);
  374.    
  375.     var removeButtonsArray = [];
  376.     for (var j = 1; j <= 5; j++) {
  377.         var itemBtn = createColorButton("项目" + j, 52, 152, 219);
  378.         removeButtonsArray.push(itemBtn);
  379.         removeHorizontal.addView(itemBtn);
  380.     }
  381.    
  382.     var removeStatus = new Label();
  383.     removeStatus.setText("当前控件数量: " + removeButtonsArray.length);
  384.     removeStatus.setTextColor(231, 76, 60);
  385.     removeStatus.setFontSize(14);
  386.    
  387.     var removeBtn = new Button();
  388.     removeBtn.setText("移除第一个");
  389.     removeBtn.setColor(231, 76, 60);
  390.     removeBtn.setTextColor(255, 255, 255);
  391.     removeBtn.setWidth(120);
  392.     removeBtn.setHeight(40);
  393.     removeBtn.onClick(function() {
  394.         if (removeButtonsArray.length > 0) {
  395.             removeButtonsArray.shift();
  396.             removeHorizontal.clearAllViews();
  397.             for (var k = 0; k < removeButtonsArray.length; k++) {
  398.                 removeHorizontal.addView(removeButtonsArray[k]);
  399.             }
  400.             removeStatus.setText("当前控件数量: " + removeButtonsArray.length);
  401.             printl("移除控件,剩余数量: " + removeButtonsArray.length);
  402.         }
  403.     });
  404.    
  405.     removeContainer.addView(removeHorizontal);
  406.     removeContainer.addView(removeStatus);
  407.     removeContainer.addView(removeBtn);
  408.    
  409.     dynamicPage.addView(removeContainer);
  410.    
  411.     // 清空控件演示
  412.     var clearSection = createSubSection("清空所有控件");
  413.     dynamicPage.addView(clearSection);
  414.    
  415.     var clearContainer = new Vertical();
  416.     clearContainer.setSpacing(10);
  417.    
  418.     var clearHorizontal = new Horizontal();
  419.     clearHorizontal.setSpacing(10);
  420.     clearHorizontal.setAlignment("center");
  421.     clearHorizontal.setBackgroundColor(240, 240, 240);
  422.    
  423.     var clearButtonsArray = [];
  424.     for (var k = 1; k <= 4; k++) {
  425.         var clearItemBtn = createColorButton("清" + k, 155, 89, 182);
  426.         clearButtonsArray.push(clearItemBtn);
  427.         clearHorizontal.addView(clearItemBtn);
  428.     }
  429.    
  430.     var clearStatus = new Label();
  431.     clearStatus.setText("当前控件数量: " + clearButtonsArray.length);
  432.     clearStatus.setTextColor(155, 89, 182);
  433.     clearStatus.setFontSize(14);
  434.    
  435.     var clearBtn = new Button();
  436.     clearBtn.setText("清空所有");
  437.     clearBtn.setColor(155, 89, 182);
  438.     clearBtn.setTextColor(255, 255, 255);
  439.     clearBtn.setWidth(120);
  440.     clearBtn.setHeight(40);
  441.     clearBtn.onClick(function() {
  442.         clearButtonsArray = [];
  443.         clearHorizontal.clearAllViews();
  444.         clearStatus.setText("当前控件数量: " + clearButtonsArray.length);
  445.         
  446.         var emptyLabel = new Label();
  447.         emptyLabel.setText("已清空所有控件");
  448.         emptyLabel.setTextColor(150, 150, 150);
  449.         emptyLabel.setFontSize(12);
  450.         clearHorizontal.addView(emptyLabel);
  451.         
  452.         printl("清空所有控件");
  453.     });
  454.    
  455.     clearContainer.addView(clearHorizontal);
  456.     clearContainer.addView(clearStatus);
  457.     clearContainer.addView(clearBtn);
  458.    
  459.     dynamicPage.addView(clearContainer);
  460.    
  461.     // 获取控件数量演示
  462.     var countSection = createSubSection("获取控件数量");
  463.     dynamicPage.addView(countSection);
  464.    
  465.     var countContainer = new Vertical();
  466.     countContainer.setSpacing(10);
  467.    
  468.     var countHorizontal = new Horizontal();
  469.     countHorizontal.setSpacing(10);
  470.     countHorizontal.setAlignment("center");
  471.     countHorizontal.setBackgroundColor(240, 240, 240);
  472.    
  473.     var countButtonsArray = [];
  474.     for (var m = 1; m <= 3; m++) {
  475.         var countItemBtn = createColorButton("计数" + m, 241, 196, 15);
  476.         countButtonsArray.push(countItemBtn);
  477.         countHorizontal.addView(countItemBtn);
  478.     }
  479.    
  480.     var countResult = new Label();
  481.     countResult.setText("点击按钮查看数量");
  482.     countResult.setTextColor(241, 196, 15);
  483.     countResult.setFontSize(14);
  484.    
  485.     var countBtn = new Button();
  486.     countBtn.setText("获取数量");
  487.     countBtn.setColor(241, 196, 15);
  488.     countBtn.setTextColor(255, 255, 255);
  489.     countBtn.setWidth(120);
  490.     countBtn.setHeight(40);
  491.     countBtn.onClick(function() {
  492.         countResult.setText("当前控件数量: " + countButtonsArray.length);
  493.         printl("获取控件数量: " + countButtonsArray.length);
  494.     });
  495.    
  496.     countContainer.addView(countHorizontal);
  497.     countContainer.addView(countResult);
  498.     countContainer.addView(countBtn);
  499.    
  500.     dynamicPage.addView(countContainer);
  501.    
  502.     tab.addView(2, dynamicPage);
  503.    
  504.     // ====================== 第四页:嵌套布局 ======================
  505.     var nestedPage = new Vertical();
  506.     nestedPage.setSpacing(8);
  507.     nestedPage.setBackgroundColor(248, 252, 250);
  508.    
  509.     var nestedHeader = createSectionHeader("嵌套布局演示", 230, 126, 34);
  510.     nestedPage.addView(nestedHeader);
  511.    
  512.     var nestedDesc = new Label();
  513.     nestedDesc.setText("展示Horizontal与Vertical容器的嵌套组合,实现复杂布局");
  514.     nestedDesc.setTextColor(100, 100, 100);
  515.     nestedDesc.setFontSize(13);
  516.     nestedDesc.setTextAlignment("center");
  517.     nestedPage.addView(nestedDesc);
  518.    
  519.     // 卡片式布局
  520.     var cardSection = createSubSection("卡片式布局");
  521.     nestedPage.addView(cardSection);
  522.    
  523.     var cardContainer = new Vertical();
  524.     cardContainer.setSpacing(12);
  525.    
  526.     for (var n = 1; n <= 3; n++) {
  527.         var card = new Vertical();
  528.         card.setSpacing(8);
  529.         card.setBackgroundColor(255, 255, 255);
  530.         
  531.         var cardHeader = new Horizontal();
  532.         cardHeader.setSpacing(10);
  533.         cardHeader.setBackgroundColor(52, 152, 219);
  534.         
  535.         var cardTitle = new Label();
  536.         cardTitle.setText("卡片标题 " + n);
  537.         cardTitle.setTextColor(255, 255, 255);
  538.         cardTitle.setFontSize(16);
  539.         cardHeader.addView(cardTitle);
  540.         
  541.         var cardContent = new Horizontal();
  542.         cardContent.setSpacing(15);
  543.         cardContent.setAlignment("center");
  544.         
  545.         var content1 = createCardItem("图标" + n + "A", 52, 152, 219);
  546.         var content2 = createCardItem("图标" + n + "B", 46, 204, 113);
  547.         var content3 = createCardItem("图标" + n + "C", 155, 89, 182);
  548.         
  549.         cardContent.addView(content1);
  550.         cardContent.addView(content2);
  551.         cardContent.addView(content3);
  552.         
  553.         card.addView(cardHeader);
  554.         card.addView(cardContent);
  555.         
  556.         cardContainer.addView(card);
  557.     }
  558.    
  559.     nestedPage.addView(cardContainer);
  560.    
  561.     // 表格式布局
  562.     var tableSection = createSubSection("表格式布局");
  563.     nestedPage.addView(tableSection);
  564.    
  565.     var tableContainer = new Vertical();
  566.     tableContainer.setSpacing(8);
  567.     tableContainer.setBackgroundColor(255, 255, 255);
  568.    
  569.     var tableHeader = new Horizontal();
  570.     tableHeader.setSpacing(5);
  571.     tableHeader.setBackgroundColor(52, 73, 94);
  572.    
  573.     var headers = ["列1", "列2", "列3", "列4"];
  574.     for (var p = 0; p < headers.length; p++) {
  575.         var headerLabel = new Label();
  576.         headerLabel.setText(headers[p]);
  577.         headerLabel.setTextColor(255, 255, 255);
  578.         headerLabel.setFontSize(14);
  579.         headerLabel.setTextAlignment("center");
  580.         headerLabel.setWidth(80);
  581.         tableHeader.addView(headerLabel);
  582.     }
  583.    
  584.     tableContainer.addView(tableHeader);
  585.    
  586.     for (var q = 1; q <= 4; q++) {
  587.         var tableRow = new Horizontal();
  588.         tableRow.setSpacing(5);
  589.         if (q % 2 === 0) {
  590.             tableRow.setBackgroundColor(248, 249, 250);
  591.         } else {
  592.             tableRow.setBackgroundColor(255, 255, 255);
  593.         }
  594.         
  595.         for (var r = 1; r <= 4; r++) {
  596.             var cellLabel = new Label();
  597.             cellLabel.setText("数据" + q + "-" + r);
  598.             cellLabel.setTextColor(80, 80, 80);
  599.             cellLabel.setFontSize(12);
  600.             cellLabel.setTextAlignment("center");
  601.             cellLabel.setWidth(80);
  602.             tableRow.addView(cellLabel);
  603.         }
  604.         
  605.         tableContainer.addView(tableRow);
  606.     }
  607.    
  608.     nestedPage.addView(tableContainer);
  609.    
  610.     // 工具栏布局
  611.     var toolbarSection = createSubSection("工具栏布局");
  612.     nestedPage.addView(toolbarSection);
  613.    
  614.     var toolbarContainer = new Vertical();
  615.     toolbarContainer.setSpacing(10);
  616.    
  617.     var toolbar = new Horizontal();
  618.     toolbar.setSpacing(5);
  619.     toolbar.setAlignment("center");
  620.     toolbar.setBackgroundColor(44, 62, 80);
  621.    
  622.     var tools = [
  623.         {text: "新建", color: 46, g: 204, b: 113},
  624.         {text: "打开", color: 52, g: 152, b: 219},
  625.         {text: "保存", color: 241, g: 196, b: 15},
  626.         {text: "删除", color: 231, g: 76, b: 60}
  627.     ];
  628.    
  629.     for (var s = 0; s < tools.length; s++) {
  630.         var toolBtn = new Button();
  631.         toolBtn.setText(tools[s].text);
  632.         toolBtn.setColor(tools[s].color, tools[s].g, tools[s].b);
  633.         toolBtn.setTextColor(255, 255, 255);
  634.         toolBtn.setWidth(70);
  635.         toolBtn.setHeight(35);
  636.         
  637.         // 添加点击事件
  638.         var btnText = tools[s].text;
  639.         toolBtn.onClick(function() {
  640.             printl("工具栏按钮点击: " + btnText);
  641.             
  642.             // 显示提示信息
  643.             var toast = new Toast();
  644.             toast.setText(btnText + " 被点击");
  645.             toast.show(1000);
  646.         });
  647.         
  648.         toolbar.addView(toolBtn);
  649.     }
  650.    
  651.     toolbarContainer.addView(toolbar);
  652.    
  653.     nestedPage.addView(toolbarContainer);
  654.    
  655.     tab.addView(3, nestedPage);
  656.    
  657.     // ====================== 第五页:实战应用 ======================
  658.     var appPage = new Vertical();
  659.     appPage.setSpacing(8);
  660.     appPage.setBackgroundColor(250, 248, 252);
  661.    
  662.     var appHeader = createSectionHeader("实战应用演示", 231, 76, 60);
  663.     appPage.addView(appHeader);
  664.    
  665.     var appDesc = new Label();
  666.     appDesc.setText("展示Horizontal容器在实际应用中的典型场景");
  667.     appDesc.setTextColor(100, 100, 100);
  668.     appDesc.setFontSize(13);
  669.     appDesc.setTextAlignment("center");
  670.     appPage.addView(appDesc);
  671.    
  672.     // 场景1:底部导航栏
  673.     var navSection = createSubSection("底部导航栏");
  674.     appPage.addView(navSection);
  675.    
  676.     var navBar = new Horizontal();
  677.     navBar.setSpacing(0);
  678.     navBar.setBackgroundColor(255, 255, 255);
  679.    
  680.     var navItems = [
  681.         {icon: "首页", color: 52, g: 152, b: 219},
  682.         {icon: "发现", color: 150, g: 150, b: 150},
  683.         {icon: "消息", color: 150, g: 150, b: 150},
  684.         {icon: "我的", color: 150, g: 150, b: 150}
  685.     ];
  686.    
  687.     for (var t = 0; t < navItems.length; t++) {
  688.         var navItem = new Vertical();
  689.         navItem.setSpacing(3);
  690.         navItem.setAlignment("center");
  691.         navItem.setBackgroundColor(255, 255, 255);
  692.         
  693.         var navIcon = new Label();
  694.         navIcon.setText(navItems[t].icon);
  695.         navIcon.setTextColor(navItems[t].color, navItems[t].g, navItems[t].b);
  696.         navIcon.setFontSize(12);
  697.         navIcon.setTextAlignment("center");
  698.         
  699.         navItem.addView(navIcon);
  700.         navBar.addView(navItem);
  701.     }
  702.    
  703.     appPage.addView(navBar);
  704.    
  705.     // 场景2:用户信息栏
  706.     var userInfoSection = createSubSection("用户信息栏");
  707.     appPage.addView(userInfoSection);
  708.    
  709.     var userInfoBar = new Horizontal();
  710.     userInfoBar.setSpacing(15);
  711.     userInfoBar.setBackgroundColor(255, 255, 255);
  712.    
  713.     var avatar = new Label();
  714.     avatar.setText("头像");
  715.     avatar.setTextColor(255, 255, 255);
  716.     avatar.setFontSize(14);
  717.     avatar.setTextAlignment("center");
  718.     avatar.setBackgroundColor(52, 152, 219);
  719.     avatar.setWidth(60);
  720.     avatar.setHeight(60);
  721.    
  722.     var userInfoText = new Vertical();
  723.     userInfoText.setSpacing(5);
  724.     userInfoText.setAlignment("left");
  725.    
  726.     var userName = new Label();
  727.     userName.setText("用户名称");
  728.     userName.setTextColor(50, 50, 50);
  729.     userName.setFontSize(16);
  730.    
  731.     var userDesc = new Label();
  732.     userDesc.setText("这是用户的个人简介描述");
  733.     userDesc.setTextColor(150, 150, 150);
  734.     userDesc.setFontSize(12);
  735.    
  736.     userInfoText.addView(userName);
  737.     userInfoText.addView(userDesc);
  738.    
  739.     var followBtn = new Button();
  740.     followBtn.setText("关注");
  741.     followBtn.setColor(231, 76, 60);
  742.     followBtn.setTextColor(255, 255, 255);
  743.     followBtn.setWidth(80);
  744.     followBtn.setHeight(35);
  745.    
  746.     userInfoBar.addView(avatar);
  747.     userInfoBar.addView(userInfoText);
  748.     userInfoBar.addView(followBtn);
  749.    
  750.     appPage.addView(userInfoBar);
  751.    
  752.     // 场景3:标签选择器
  753.     var tagSection = createSubSection("标签选择器");
  754.     appPage.addView(tagSection);
  755.    
  756.     var tagContainer = new Horizontal();
  757.     tagContainer.setSpacing(10);
  758.     tagContainer.setAlignment("center");
  759.     tagContainer.setBackgroundColor(255, 255, 255);
  760.    
  761.     var tags = ["热门", "推荐", "最新", "精选", "关注"];
  762.     var tagColors = [
  763.         [231, 76, 60],
  764.         [46, 204, 113],
  765.         [52, 152, 219],
  766.         [155, 89, 182],
  767.         [241, 196, 15]
  768.     ];
  769.    
  770.     for (var u = 0; u < tags.length; u++) {
  771.         var tagBtn = new Button();
  772.         tagBtn.setText(tags[u]);
  773.         tagBtn.setColor(tagColors[u][0], tagColors[u][1], tagColors[u][2]);
  774.         tagBtn.setTextColor(255, 255, 255);
  775.         tagBtn.setWidth(60);
  776.         tagBtn.setHeight(30);
  777.         tagContainer.addView(tagBtn);
  778.     }
  779.    
  780.     appPage.addView(tagContainer);
  781.    
  782.     // 场景4:评分组件
  783.     var ratingSection = createSubSection("评分组件");
  784.     appPage.addView(ratingSection);
  785.    
  786.     var ratingContainer = new Horizontal();
  787.     ratingContainer.setSpacing(5);
  788.     ratingContainer.setAlignment("center");
  789.     ratingContainer.setBackgroundColor(255, 255, 255);
  790.    
  791.     for (var v = 1; v <= 5; v++) {
  792.         var star = new Label();
  793.         star.setText("★");
  794.         if (v <= 4) {
  795.             star.setTextColor(241, 196, 15);
  796.         } else {
  797.             star.setTextColor(200, 200, 200);
  798.         }
  799.         star.setFontSize(24);
  800.         star.setTextAlignment("center");
  801.         ratingContainer.addView(star);
  802.     }
  803.    
  804.     var ratingText = new Label();
  805.     ratingText.setText("4.0分");
  806.     ratingText.setTextColor(80, 80, 80);
  807.     ratingText.setFontSize(14);
  808.     ratingContainer.addView(ratingText);
  809.    
  810.     appPage.addView(ratingContainer);
  811.    
  812.     // 场景5:进度指示器
  813.     var progressSection = createSubSection("步骤指示器");
  814.     appPage.addView(progressSection);
  815.    
  816.     var progressContainer = new Horizontal();
  817.     progressContainer.setSpacing(10);
  818.     progressContainer.setAlignment("center");
  819.     progressContainer.setBackgroundColor(255, 255, 255);
  820.    
  821.     var steps = ["步骤1", "步骤2", "步骤3", "步骤4"];
  822.     var stepStatus = [true, true, false, false];
  823.    
  824.     for (var w = 0; w < steps.length; w++) {
  825.         if (w > 0) {
  826.             var line = new Label();
  827.             line.setText("→");
  828.             line.setTextColor(200, 200, 200);
  829.             line.setFontSize(16);
  830.             progressContainer.addView(line);
  831.         }
  832.         
  833.         var stepLabel = new Label();
  834.         stepLabel.setText(steps[w]);
  835.         if (stepStatus[w]) {
  836.             stepLabel.setTextColor(46, 204, 113);
  837.         } else {
  838.             stepLabel.setTextColor(200, 200, 200);
  839.         }
  840.         stepLabel.setFontSize(12);
  841.         progressContainer.addView(stepLabel);
  842.     }
  843.    
  844.     appPage.addView(progressContainer);
  845.    
  846.     // 退出按钮
  847.     var exitContainer = new Horizontal();
  848.     exitContainer.setAlignment("center");
  849.     exitContainer.setBackgroundColor(250, 248, 252);
  850.    
  851.     var exitBtn = new Button();
  852.     exitBtn.setText("退出示例");
  853.     exitBtn.setColor(231, 76, 60);
  854.     exitBtn.setTextColor(255, 255, 255);
  855.     exitBtn.setWidth(150);
  856.     exitBtn.setHeight(45);
  857.     exitBtn.onClick(function() {
  858.         printl("退出按钮被点击");
  859.         tab.dismiss();
  860.     });
  861.    
  862.     exitContainer.addView(exitBtn);
  863.     appPage.addView(exitContainer);
  864.    
  865.     tab.addView(4, appPage);
  866.    
  867.     printl("Horizontal水平容器示例界面构建完成");
  868. });

  869. // ====================== 辅助函数 ======================

  870. function createSectionHeader(text, r, g, b) {
  871.     var header = new Horizontal();
  872.     header.setAlignment("center");
  873.     header.setBackgroundColor(r, g, b);
  874.    
  875.     var label = new Label();
  876.     label.setText(text);
  877.     label.setTextColor(255, 255, 255);
  878.     label.setFontSize(18);
  879.     label.setHeight(35);
  880.     header.addView(label);
  881.    
  882.     return header;
  883. }

  884. function createSubSection(text) {
  885.     var section = new Horizontal();
  886.     section.setAlignment("center");
  887.     section.setBackgroundColor(220, 220, 225);
  888.    
  889.     var label = new Label();
  890.     label.setText(text);
  891.     label.setTextColor(60, 60, 60);
  892.     label.setFontSize(15);
  893.     section.addView(label);
  894.    
  895.     return section;
  896. }

  897. function createColorButton(text, r, g, b) {
  898.     var btn = new Button();
  899.     btn.setText(text);
  900.     btn.setColor(r, g, b);
  901.     btn.setTextColor(255, 255, 255);
  902.     btn.setWidth(80);
  903.     btn.setHeight(40);
  904.     btn.onClick(function() {
  905.         printl("按钮[" + text + "]被点击");
  906.     });
  907.     return btn;
  908. }

  909. function createAlignLabel(text, r, g, b) {
  910.     var label = new Label();
  911.     label.setText(text);
  912.     label.setTextColor(255, 255, 255);
  913.     label.setFontSize(14);
  914.     label.setTextAlignment("center");
  915.     label.setBackgroundColor(r, g, b);
  916.     label.setWidth(60);
  917.     label.setHeight(35);
  918.     return label;
  919. }

  920. function addDemoLabels(container, labels) {
  921.     for (var i = 0; i < labels.length; i++) {
  922.         var label = new Label();
  923.         label.setText(labels[i]);
  924.         label.setTextColor(80, 80, 80);
  925.         label.setFontSize(12);
  926.         label.setTextAlignment("center");
  927.         label.setWidth(120);
  928.         label.setHeight(30);
  929.         container.addView(label);
  930.     }
  931. }

  932. function addWhiteLabels(container, labels) {
  933.     for (var i = 0; i < labels.length; i++) {
  934.         var label = new Label();
  935.         label.setText(labels[i]);
  936.         label.setTextColor(255, 255, 255);
  937.         label.setFontSize(12);
  938.         label.setTextAlignment("center");
  939.         label.setWidth(120);
  940.         label.setHeight(30);
  941.         container.addView(label);
  942.     }
  943. }

  944. function createCardItem(text, r, g, b) {
  945.     var item = new Vertical();
  946.     item.setSpacing(5);
  947.     item.setAlignment("center");
  948.     item.setBackgroundColor(r, g, b);
  949.    
  950.     var icon = new Label();
  951.     icon.setText(text);
  952.     icon.setTextColor(255, 255, 255);
  953.     icon.setFontSize(14);
  954.     icon.setTextAlignment("center");
  955.    
  956.     item.addView(icon);
  957.     return item;
  958. }

  959. printl("Horizontal水平容器完整示例已启动");
复制代码







欢迎光临 B2B网络软件 (http://bbs.niubt.cn/) Powered by Discuz! X3.2