Ext Js 列布局-- ColumnLayout

1:Ext.layout.ColumnLayout

    它是为构建某个垂直式结构而准备的布局,当中包含已指定宽度的多个列,可以使用columnWidth或者width来指定子元素所占的列宽度

    属性width总是以像素来固定宽度,并必须是数字大于或者等于1,属性columnWidth是百分比相对单位,并必须是百分比字符串区间是大于0小于1

    使用columnWidth属性来分配列时,columnWidth加起来必须是等于1(或110%),否则渲染出来的布局可能会出现不正常。 

 

2:指定列宽度的三种方式

 第一:通过width属性来指定列宽度

  

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>使用width属性指定列宽度</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.       
  20.     <link rel="stylesheet" type="text/css" href="ext3.2/resources/css/ext-all.css"></link>  
  21.     <script type="text/javascript" src="ext3.2/adapter/ext/ext-base.js"></script>  
  22.     <script type="text/javascript" src="ext3.2/ext-all.js"></script>  
  23.     <script type="text/javascript" src="ext3.2/src/local/ext-lang-zh_CN.js"></script>  
  24.       
  25.     <script type="text/javascript">  
  26.         Ext.onReady(function() {  
  27.              new Ext.Panel({  
  28.                   renderTo: 'column',  
  29.                   width: 500,  
  30.                   height: 150,  
  31.                   title: 'Columnayout',  
  32.                   layout: 'column',    //指定布局方式为column  
  33.                   defaults: {  
  34.                        bodyStyle: 'background-color: #FFFFFF',  //设置面板的背景色  
  35.                        frame: true  
  36.                   },  
  37.                   frame: true,  
  38.                   items: [  
  39.                       {title: 'first', html: '第一列', width: 200, height: 100},  
  40.                       {title: 'second', html: '第二列', width: 200, height: 100},  
  41.                   ]  
  42.   });  
  43.         });  
  44.     </script>  
  45.   </head>  
  46.   <body>  
  47.     <div id="column"></div>  
  48.   </body>  
  49. </html>  


程序效果:

 

    通过设置子面板的width属性,来设定固定的列宽度分别为200、200以及剩余的宽度。

 

第二:columnWidth属性指定列宽度

 代码:

 

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>columnWidth属性指定列宽度</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.       
  20.     <link rel="stylesheet" type="text/css" href="ext3.2/resources/css/ext-all.css"></link>  
  21.     <script type="text/javascript" src="ext3.2/adapter/ext/ext-base.js"></script>  
  22.     <script type="text/javascript" src="ext3.2/ext-all.js"></script>  
  23.     <script type="text/javascript" src="ext3.2/src/local/ext-lang-zh_CN.js"></script>  
  24.       
  25.     <script type="text/javascript">  
  26.         Ext.onReady(function() {  
  27.              new Ext.Panel({  
  28.                   renderTo: 'column',  
  29.                   width: 500,  
  30.                   height: 150,  
  31.                   title: 'Columnayout',  
  32.                   layout: 'column',    //指定布局方式为column  
  33.                   frame: true,  
  34.                   defaults: {  
  35.                        bodyStyle: 'background-color: #FFFFFF',  //设置面板的背景色  
  36.                        frame: true  
  37.                   },  
  38.                   items: [  //通过columnWidth属性来指定宽占容器的百分比  
  39.                       {title: 'first', html: '第一列', columnWidth: 0.4, height: 100},  
  40.                       {title: 'second', html: '第二列', columnWidth: 0.6, height: 100},  
  41.                   ]  
  42.   });  
  43.         });  
  44.     </script>  
  45.   </head>  
  46.   <body>  
  47.     <div id="column"></div>  
  48.   </body>  
  49. </html>  


程序效果图:

 

第三: width和columnWidth属性指定列宽度

 

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>columnWidth属性指定列宽度</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.       
  20.     <link rel="stylesheet" type="text/css" href="ext3.2/resources/css/ext-all.css"></link>  
  21.     <script type="text/javascript" src="ext3.2/adapter/ext/ext-base.js"></script>  
  22.     <script type="text/javascript" src="ext3.2/ext-all.js"></script>  
  23.     <script type="text/javascript" src="ext3.2/src/local/ext-lang-zh_CN.js"></script>  
  24.       
  25.     <script type="text/javascript">  
  26.         Ext.onReady(function() {  
  27.              new Ext.Panel({  
  28.                   renderTo: 'column',  
  29.                   width: 500,  
  30.                   height: 150,  
  31.                   title: 'Columnayout',  
  32.                   layout: 'column',    //指定布局方式为column  
  33.                   frame: true,  
  34.                   defaults: {  
  35.                        bodyStyle: 'background-color: #FFFFFF',  //设置面板的背景色  
  36.                        frame: true,  
  37.                        height: 100  
  38.                   },  
  39.                   items: [    
  40.                       {title: 'first', html: '第一列', width: 150},    // 指定列宽度为150像素    
  41.                       {title: 'second', html: '第二列', columnWidth: 0.4},   //指定列宽度为剩下宽度的40%  
  42.                       {title: 'third', html: '第三列', columnWidth: 0.6}     //指定列宽度为剩下宽度的60%  
  43.                   ]  
  44.              });  
  45.         });  
  46.     </script>  
  47.   </head>  
  48.   <body>  
  49.     <div id="column"></div>  
  50.   </body>  
  51. </html>  


程序效果:

  设置panel的宽度为500,

 第一列宽度=150(因为第一列是通过width配置项指定的固定值)

 第二列宽度=(500-150)* 0.4 (按比例分割剩余宽度)

 第三列宽度=(500-150)* 0.6(说明:按比例分割剩余宽度)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值