# Grid Layout The **\** component is the root container of the grid layout. Within the root container, you can use **\** and **\** for the grid layout. For details, see [Grid-container](../reference/arkui-js/js-components-grid-container.md). ## Creating a \ Component Create a **\** component in the .hml file under **pages/index** and add a [\](../reference/arkui-js/js-components-grid-row.md) child component. ```html
``` ```css /* xxx.css */ .container{ flex-direction: column; background-color: #F1F3F5; width: 100%; height: 100%; justify-content: center; align-items: center; } ``` ![en-us_image_0000001276162725](figures/en-us_image_0000001276162725.png) > **NOTE** > > **\** supports only **\** as a child component. ## Methods Touch the **\** component to call the **getColumns**, **getColumnWidth**, and **getGutterWidth** methods to return the number of columns in the grid container, and column width and gutter width of the grid container. Press and hold the component to call the **getSizeType** method to return the size-responsive type of the grid container (**xs**|**sm**|**md**|**lg**). ```html
``` ```css /* xxx.css */ .container{ flex-direction: column; background-color: #F1F3F5; width: 100%; height: 100%; justify-content: center; align-items: center; } ``` ```js // index.js import promptAction from '@ohos.promptAction'; export default { data:{ gutterWidth:'', columnWidth:'', columns:'', }, getColumns(){ this.$element('mygrid').getColumnWidth((result)=>{ this.columnWidth = result; }) this.$element('mygrid').getGutterWidth((result)=>{ this.gutterWidth = result; }) this.$element('mygrid').getColumns((result)=>{ this.columns= result; }) setTimeout(()=>{ promptAction.showToast({duration:5000,message:'columnWidth:'+this.columnWidth+',gutterWidth:'+ this.gutterWidth+',getColumns:'+this.columns}) }) }, getSizeType(){ this.$element('mygrid').getSizeType((result)=>{ promptAction.showToast({duration:2000,message:'get size type:'+result}) }) }, } ``` ![en-us_image_0000001231843088](figures/en-us_image_0000001231843088.gif) ## Adding \ After adding a **\** child component to **\**, add a **\** child component to **\** to form a layout. ```html
top
left
right
bottom
``` ```css /* xxx.css */ .container{ flex-direction: column; background-color: #F1F3F5; width: 100%; height: 100%; justify-content: center; align-items: center; } text{ color: white; font-size: 40px; ``` ![en-us_image_0000001231683124](figures/en-us_image_0000001231683124.png) > **NOTE** > > **\** supports only **\** as a child component. You can add content only to **\**. ## Example Scenario In this example, the content in the list is output cyclically to create a grid layout. When the user pulls down the screen, the **refresh** method is triggered. In this case, a piece of data is added to the list and **setTimeout** is set to refresh the request data. ```html
image{{item.id}}
``` ```css /* xxx.css */ .container{ flex-direction: column; background-color: #F1F3F5; width: 100%; height: 100%; } text{ color: #0a0aef; font-size: 60px; } ``` ```js // index.js import prompt from '@system.prompt'; export default { data:{ list:[ {src:'common/images/1.png',id:'1'}, {src:'common/images/2.png',id:'2'}, {src:'common/images/3.png',id:'3'} ], fresh:false }, refresh(e) { prompt.showToast({ message: 'refreshing' }) var that = this; that.fresh = e.refreshing; setTimeout(function () { that.fresh = false; that.list.unshift({src: 'common/images/4.png',id:'4'}); prompt.showToast({ message: 'succeed' }) }, 2000) } } ``` ![en-us_image_0000001276003501](figures/en-us_image_0000001276003501.gif)