gpt4 book ai didi

javascript - GAS : How to get a vertical panel centered in the screen of a standalone app? (`TypeError: Can not read the "CENTER“未定义的属性。`)

转载 作者:行者123 更新时间:2023-12-02 17:07:42 25 4
gpt4 key购买 nike

我正在编写我的第一个独立 GAS 应用程序!我正在使用电子表格脚本的一些代码来完成此操作。我正在阅读 Serge Insas book 的标题。我发现它非常好,向我澄清了一些概念,现在我对这些概念有了更好的理解。但我在垂直面板对齐方面遇到问题(在我的电子表格脚本中,它自动在中心对齐)。我希望面板显示在中心(默认情况下显示在屏幕的左上角)。我使面板居中,但 UiApp 未居中。因此,这表明丑陋的双滚动条需要用户手动将面板居中。看完this answer ,我写这段代码:

function doGet() {  
var app = UiApp.createApplication().setHeight(1400).setWidth(1800);
//var _imgCSS = {'position':'relative', 'left':'200PX', 'top':'200PX'}
var panel = app.createVerticalPanel().setStyleAttributes(_imgCSS)
.setHorizontalAlignment(UiApp.HorizontalAlignment.CENTER)
.fullPanel.setVerticalAlignment(UiApp.VerticalAlignment.MIDDLE);

但是我收到一个错误(以我的语言):TypeError: 无法读取未定义的“CENTER”属性。

如何解决这个问题并以简单的方式在独立应用程序的屏幕上居中设置垂直面板?

编辑:我注意到,如果我更改此行的值:

  var app = UiApp.createApplication().setHeight(1400).setWidth(1800);

为此

  var app = UiApp.createApplication().setHeight(140).setWidth(180);

我没有注意到任何变化(在滚动条中)。如何扩大应用范围? (我认为这会解决我的垂直面板问题)

最佳答案

您可以以百分比定义宽度和高度,这将解决滚动条问题。

然后使用主父面板,如以下代码所示:

function doGet() {  
var app = UiApp.createApplication();
var main = app.createVerticalPanel().setStyleAttributes({'background':'beige'}).setWidth('100%').setHeight('100%').setHorizontalAlignment(UiApp.HorizontalAlignment.CENTER);
var panel = app.createVerticalPanel().setStyleAttributes({'background':'red'}).setWidth('400').setHeight('800');
var label = app.createLabel('test label');
app.add(main);
main.add(panel);
panel.add(label)
return app;
}

test here

enter image description here

关于javascript - GAS : How to get a vertical panel centered in the screen of a standalone app? (`TypeError: Can not read the "CENTER“未定义的属性。`),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25098766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com