如何中心元素谷歌应用程序脚本UiApp [英] How to center elements google apps script UiApp

查看:122
本文介绍了如何中心元素谷歌应用程序脚本UiApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用图像创建一个简单的应用程序。我创建了这样的应用程序:

I am creating a simple app with an image. I create the app like so:

function createApplication(){
  var app = UiApp.createApplication().setTitle("My Simple App");
  mainImage = app.createImage("URL TO IMAGE");
  app.add(mainImage);
  return(app);
}

这会将图像放在屏幕的左上角。有人可以告诉我如何使图像居中?

This puts the image to the top left of the screen. Can someone show me how to center the image ?

非常感谢

Many thanks

推荐答案

<您可以使用 setStyleAttribute()并参考一些 CSS文档

像这样尝试它(我真的不是CSS的专家,所以不要责怪我,如果它不雅; - )

try it like this for example (I'm really not an expert in CSS so don't blame me if it is inelegant ;-)

function testImage(){
  var app = UiApp.createApplication().setTitle("My Simple App").setHeight('700').setWidth('900');
  mainImage = app.createImage("https://dl.dropbox.com/u/211279/Time-change-clock_animated_TR80.gif")
  .setStyleAttribute('position','relative').setStyleAttribute('left','50%').setStyleAttribute('top','50%')
  app.add(mainImage);
  ss=SpreadsheetApp.getActive()
  ss.show(app)
}

注意:您也可以使用PX(像素)而不是%定位图像,正如您注意到的那样,我在电子表格用户界面中测试了它。

Note : You can also position your image using PX(pixels) instead of % and, as you noticed, I tested this in a spreadsheet UI.

编辑:这里是一个使用像素和布赖恩建议的CSS样式的版本,更紧凑,语法接近原始的CSS方法(thx再次):

EDIT : and here is a version using pixels and Bryan's suggestion for CSS styling, more compact and with a syntax that approaches the original CSS method (thx again) :

var _imgCSS = {'position':'relative', 'left':'200PX', 'top':'200PX'}

function testImage(){
      var app = UiApp.createApplication().setTitle("My Simple App").setHeight('500').setWidth('500');
      var mainImage = app.createImage("https://dl.dropbox.com/u/211279/Time-change-clock_animated_TR80.gif")
      .setStyleAttributes(_imgCSS)
      app.add(mainImage);
      ss=SpreadsheetApp.getActive()
      ss.show(app)
    }

这篇关于如何中心元素谷歌应用程序脚本UiApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆