问题
As we cant set the width in percentage in ExtendScript.
I am finding a way where my button can be stretch/resize in realtime while resizing the panel size.
I tried setting the fill value -
Button.preferredSize.width = 200;
Button.preferredSize.height = 80;
saveButton.alignment = ['fill', 'fill'];
Didn't worked. Tried matching button width to panel width
Button.preferredSize.width = panel.width;
Didn't worked.
回答1:
Just set it's alignment to fill horizontally.
You can also specify it's size/ preferredSize and change it's default height.
Also, in order the UI to resize you need to add "onResizing/ onResize" event listeners and tell the layout to resize with resize()
.
Here's an example:
function myPanel (thisObj)
{
var win = {};
win.pal = thisObj instanceof Panel ? thisObj : new Window('palette', '', undefined, {resizeable: true});
if (win.pal === null) return win.pal;
var res = "Group {orientation: 'column', alignment: ['fill', 'fill'], preferredSize: [128, 64], \
myButton: Button {text: 'My Button Name', alignment: ['fill', 'center']}\
}";
win.ui = win.pal.add(res);
win.ui.myButton.minimumSize = [128, 32];
win.pal.layout.layout(true);
win.pal.onResizing = win.pal.onResize = function ()
{
this.layout.resize();
};
if (win.pal !== null && win.pal instanceof Window)
{
win.pal.show();
}
return win;
}
myPanel(this);
EDIT: You can set the button's width in percentage too, by taking it's container size. E.g.: win.ui.myButton.size = [ 0.9 * win.ui.size[0], 32];
来源:https://stackoverflow.com/questions/60009871/ae-scripting-how-to-create-a-button-in-extendscript-that-stretches-along-with