javascript 在 ExtJS 中居中对齐按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16769032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Center-align a button in ExtJS
提问by Raza Ahmed
var myWin = new Ext.Window({
height : 100,
width : 200,
maximizable : true,
items : [ {
xtype : 'button',
text : 'myButton'
// align : center
} ]
});
myWin.show();
This is my code. I want to align the button to center, i know there are ways to do that but they are a bit long and tricky, is there a simple solution like align : center
or something like that, that should align button or text fields to center?
这是我的代码。我想将按钮居中对齐,我知道有一些方法可以做到这一点,但它们有点长且棘手,是否有类似align : center
或类似的简单解决方案,应该将按钮或文本字段居中对齐?
采纳答案by Nail Shakirov
You can try this. It's one way(I add picture of my window)
你可以试试这个。这是一种方式(我添加了我的窗口图片)
Ext.define('MyApp.view.MyWindow', {
extend: 'Ext.window.Window',
height: 137,
width: 233,
layout: {
align: 'middle',
pack: 'center',
type: 'hbox'
},
title: 'My Window',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'button',
text: 'MyButton'
}
]
});
me.callParent(arguments);
}
});
回答by Raza Ahmed
Insert buttonAlign: 'center',
and it should center - the default is right
, I think. See this example.
插入buttonAlign: 'center',
,它应该居中 -right
我认为默认是。请参阅此示例。