欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Extjs学习笔记之七 布局

程序员文章站 2022-06-17 17:50:04
extjs layout browser . extjs3.1.0 版本支持17种,下面挑一些重要的简要的说明一下,要看效果,去上面给的链接,不再贴图了。给panel设置...
extjs layout browser .

extjs3.1.0 版本支持17种,下面挑一些重要的简要的说明一下,要看效果,去上面给的链接,不再贴图了。给panel设置layout的方法是一样的,就是设置panel的layout配置项。
1. absolutelayout
可以通过panel内部组件的决定位置来布局。通过x,y来指定。

示例用法:

复制代码 代码如下:

new ext.panel({
layout: 'absolute',
title: 'absulutelayout',
renderto: document.body,
frame: true,
defaulttype: 'textfield',
width: 400,
height:250,
items: [{
x: 0, y: 5,
xtype: 'label',
text: 'send to:'
},
{
x: 60, y: 0,
name: 'to'
}, {
x: 0, y: 35,
xtype: 'label',
text: 'subject:'
}, {
x: 60, y: 30,
name: 'subject'
},
{
x: 0, y: 60,
xtype: 'textarea',
name: 'msg'
}]
});

2.accordionlayout
accordion的意思是手风琴,顾名思义,这种布局可以向手风琴那样,有的组件张开,有的闭合。这种效果作为侧边栏比较有用。

示例用法:
复制代码 代码如下:

new ext.panel({
title: 'accordion layout',
layout: 'accordion',
renderto: document.body,
defaults: { // applied to each contained panel
bodystyle: 'padding:15px'
},
layoutconfig: {
// layout-specific configs go here

titlecollapse: true,
animate: true,
activeontop: false
},
items: [{
title: 'panel 1',
html: '<p>panel content!</p>'
}, {
title: 'panel 2',
html: '<p>panel content!</p>'
}, {
title: 'panel 3',
html: '<p>panel content!</p>'
}]
});
});

3. anchorlayout
这种layout非常有用,尤其是在布局含有gridview这一类控件的页面的时候,anchorlayout实际上类似于winform的form默认的布局方式,不过它仅仅可以固定某一个组件距离页面边框(右边框和底边框)的距离(绝对的像素或者相对比例)。 通过anchor属性设置,anchor属性的设置api文档上解释的十分清楚,就直接摘抄过来了:

anchor : string

this configuation option is to be applied to child items of a container managed by this layout (ie. configured withlayout:'anchor').

this value is what tells the layout how an item should be anchored to the container. items added to an anchorlayout accept an anchoring-specific config property of anchor which is a string containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%'). the following types of anchor values are supported:

percentage : any value between 1 and 100, expressed as a percentage.
the first anchor is the percentage width that the item should take up within the container, and the second is the percentage height. for example:

// two values specified
anchor: '100% 50%' // render item complete width of the container and
// 1/2 height of the container
// one value specified
anchor: '100%' // the width value; the height will default to autooffsets : any positive or negative integer value.
this is a raw adjustment where the first anchor is the offset from the right edge of the container, and the second is the offset from the bottom edge. for example:

// two values specified
anchor: '-50 -100' // render item the complete width of the container
// minus 50 pixels and
// the complete height minus 100 pixels.
// one value specified
anchor: '-50' // anchor value is assumed to be the right offset value
// bottom offset will default to 0sides : valid values are 'right' (or 'r') and 'bottom' (or 'b').
either the container must have a fixed size or an anchorsize config value defined at render time in order for these to have any effect.

mixed :
anchor values can also be mixed as needed. for example, to render the width offset from the container right edge by 50 pixels and 75% of the container's height use:

anchor: '-50 75%'不过我将anchor的第一个属性也就是offset设置成正数似乎没什么效果,虽然文档中说offsets : any positive or negative integer value.

示例用法:
复制代码 代码如下:

new ext.panel({
layout: 'anchor',
title:'anchor',
renderto: document.body,
items: [{
title: 'item 1',
html: 'content 1',
width: 800,
anchor: 'right 20%'
}, {
title: 'item 2',
html: 'content 2',
width: 300,
anchor: '50% 30%'
}, {
title: 'item 3',
html: 'content 3',
width: 600,
anchor:'-100 50%'
}]
});

4. borderlayout
borderlayout通过指定页面上的区域来布局,至少要有一个center区域,然后可以设置west,south,east,north区域,作为辅助的页面。通常适合大型页面的布局,中部为主要功能区,两侧,底部可以作为工具栏。
复制代码 代码如下:

var myborderpanel = new ext.panel({
renderto: document.body,
width: 700,
height: 500,
title: 'border layout',
layout: 'border',
items: [{
title: 'south region is resizable',
region: 'south', // position for region
height: 100,
split: true, // enable resizing
minsize: 75, // defaults to 50
maxsize: 150,
margins: '0 5 5 5'
}, {
// xtype: 'panel' implied by default
title: 'west region is collapsible',
region: 'west',
margins: '5 0 0 5',
width: 200,
collapsible: true, // make collapsible
cmargins: '5 5 0 5', // adjust top margin when collapsed
id: 'west-region-container',
layout: 'fit',
unstyled: true
}, {
title: 'center region',
region: 'center', // center region is required, no width/height specified
xtype: 'container',
layout: 'fit',
margins: '5 5 0 0'
}]
});

5. columnlayout
columnlayout可以指定面板的宽度,用width指定的是像素,columnwidth指定百分比,必须是0-1之间的数字。也可以两者都用,都用的情况下,百分比是整个页面的宽度减去固定宽度的列剩余的宽度的百分比。

示例用法:
复制代码 代码如下:

var p = new ext.panel({
title: 'column layout - mixed',
layout: 'column',
renderto: document.body,
items: [{
title: 'column 1',
columnwidth: .3,
html:'<div>hello world</div>'
}, {
title: 'column 2',
html:'<div>hello</div>',
columnwidth: .6
}, {
title: 'column 3',
columnwidth: .1,
html:'<div>hello</div><div>another line</div>'
}]
});

这个用法是和api文档以及官方例子是一样的,但是这些列的宽度确不能随着浏览器大小的改变而改变,每次总要刷新一下才能重新适应新的浏览器宽度。但是官网的例子上确实可以随着浏览器的拖动内部的面板大小也跟着变化的。很奇怪。如果有朋友知道,请指点迷津下。

布局的用法都差不多,就不再继续写下去了。关键是在实际应用中灵活选用。