1e41f4b71Sopenharmony_ci# Development of Layout Container Components<a name="EN-US_TOPIC_0000001052661991"></a> 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciLayout container components consist of basic view classes. You can set the view positions to achieve nested and overlapped layouts, set the layout type and margin to standardize the child components in the layout, and call certain functions to implement layout views based on parent and sibling components. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## UISwipeView<a name="section13631719181717"></a> 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## When to Use<a name="section11299120102617"></a> 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**UISwipeView** inherits from **UIViewGroup**. In addition to the **Add**, **Remove**, and **Insert** functions, **UISwipeView** provides the functions to swipe contents by page and center the current page after swiping. This component can be horizontally or vertically centered. Child components added via the **Add** function are automatically horizontally or vertically centered, adaptive to the **UISwipeView** direction, in the sequence they were added. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Available APIs<a name="section767434119261"></a> 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Table 1** Available functions in SwipeView 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci<a name="table143378205264"></a> 16e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row8336122032615"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p13361520162611"><a name="p13361520162611"></a><a name="p13361520162611"></a>Function</p> 17e41f4b71Sopenharmony_ci</th> 18e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p153361920112617"><a name="p153361920112617"></a><a name="p153361920112617"></a>Description</p> 19e41f4b71Sopenharmony_ci</th> 20e41f4b71Sopenharmony_ci</tr> 21e41f4b71Sopenharmony_ci</thead> 22e41f4b71Sopenharmony_ci<tbody><tr id="row9336720172616"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p83365206267"><a name="p83365206267"></a><a name="p83365206267"></a>void SetCurrentPage(uint16_t index);</p> 23e41f4b71Sopenharmony_ci</td> 24e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1833612017261"><a name="p1833612017261"></a><a name="p1833612017261"></a>Sets the current page.</p> 25e41f4b71Sopenharmony_ci</td> 26e41f4b71Sopenharmony_ci</tr> 27e41f4b71Sopenharmony_ci<tr id="row15336172002613"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p0336162072613"><a name="p0336162072613"></a><a name="p0336162072613"></a>uint16_t GetCurrentPage()</p> 28e41f4b71Sopenharmony_ci</td> 29e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p433615207262"><a name="p433615207262"></a><a name="p433615207262"></a>Obtains the current page.</p> 30e41f4b71Sopenharmony_ci</td> 31e41f4b71Sopenharmony_ci</tr> 32e41f4b71Sopenharmony_ci<tr id="row9336920102614"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p6336520102619"><a name="p6336520102619"></a><a name="p6336520102619"></a>UIView* GetCurrentView() const</p> 33e41f4b71Sopenharmony_ci</td> 34e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p16336112062612"><a name="p16336112062612"></a><a name="p16336112062612"></a>Obtains the current view.</p> 35e41f4b71Sopenharmony_ci</td> 36e41f4b71Sopenharmony_ci</tr> 37e41f4b71Sopenharmony_ci<tr id="row03371820162616"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7336172082611"><a name="p7336172082611"></a><a name="p7336172082611"></a>void SetOnSwipeListener(OnSwipeListener& onSwipeListener)</p> 38e41f4b71Sopenharmony_ci</td> 39e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p15336172012269"><a name="p15336172012269"></a><a name="p15336172012269"></a>Sets the swiping callback class.</p> 40e41f4b71Sopenharmony_ci</td> 41e41f4b71Sopenharmony_ci</tr> 42e41f4b71Sopenharmony_ci<tr id="row23371520172613"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p733792017267"><a name="p733792017267"></a><a name="p733792017267"></a>void SetAnimatorTime(uint16_t time);</p> 43e41f4b71Sopenharmony_ci</td> 44e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p16337112012613"><a name="p16337112012613"></a><a name="p16337112012613"></a>Sets the animator event.</p> 45e41f4b71Sopenharmony_ci</td> 46e41f4b71Sopenharmony_ci</tr> 47e41f4b71Sopenharmony_ci<tr id="row12337152011269"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p9337220152610"><a name="p9337220152610"></a><a name="p9337220152610"></a>void SetLoopState(bool loop)</p> 48e41f4b71Sopenharmony_ci</td> 49e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p12337172032612"><a name="p12337172032612"></a><a name="p12337172032612"></a>Sets whether to enable the cyclic state.</p> 50e41f4b71Sopenharmony_ci</td> 51e41f4b71Sopenharmony_ci</tr> 52e41f4b71Sopenharmony_ci<tr id="row1033713201266"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1933792092610"><a name="p1933792092610"></a><a name="p1933792092610"></a>UIView* GetViewByIndex(uint16_t index);</p> 53e41f4b71Sopenharmony_ci</td> 54e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p033714208263"><a name="p033714208263"></a><a name="p033714208263"></a>Obtains a view based on its index.</p> 55e41f4b71Sopenharmony_ci</td> 56e41f4b71Sopenharmony_ci</tr> 57e41f4b71Sopenharmony_ci</tbody> 58e41f4b71Sopenharmony_ci</table> 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci## Development Procedure \(Non-Cyclic Horizontal Swiping\)<a name="section111911175287"></a> 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci1. Create a horizontal swiping **UISwipeView**. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci ``` 65e41f4b71Sopenharmony_ci UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL); 66e41f4b71Sopenharmony_ci ``` 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci2. Add child components to **UISwipeView**. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci ``` 71e41f4b71Sopenharmony_ci UILabelButton* button1 = new UILabelButton(); 72e41f4b71Sopenharmony_ci button1->SetPosition(0, 0, g_ButtonW, g_ButtonH); 73e41f4b71Sopenharmony_ci button1->SetText("button1"); 74e41f4b71Sopenharmony_ci swipe->Add(button1); 75e41f4b71Sopenharmony_ci UILabelButton* button2 = new UILabelButton(); 76e41f4b71Sopenharmony_ci button2->SetPosition(0, 0, g_ButtonW, g_ButtonH); 77e41f4b71Sopenharmony_ci button2->SetText("button2"); 78e41f4b71Sopenharmony_ci swipe->Add(button2); 79e41f4b71Sopenharmony_ci UILabelButton* button3 = new UILabelButton(); 80e41f4b71Sopenharmony_ci button3->SetPosition(0, 0, g_ButtonW, g_ButtonH); 81e41f4b71Sopenharmony_ci button3->SetText("button3"); 82e41f4b71Sopenharmony_ci swipe->Add(button3); 83e41f4b71Sopenharmony_ci ``` 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci3. Verify that the components are swiping horizontally but not cyclically. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci **Figure 1** Horizontal swiping effect of **UISwipeView**<a name="fig933862020262"></a> 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci  91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci## Development Procedure \(Cyclic Horizontal Swiping\)<a name="section1976914915282"></a> 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci1. Create a horizontal swiping **UISwipeView** and add its child components. 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci ``` 98e41f4b71Sopenharmony_ci UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL); 99e41f4b71Sopenharmony_ci UILabelButton* button1 = new UILabelButton(); 100e41f4b71Sopenharmony_ci button1->SetPosition(0, 0, g_ButtonW, g_ButtonH); 101e41f4b71Sopenharmony_ci button1->SetText("button1"); 102e41f4b71Sopenharmony_ci swipe->Add(button1); 103e41f4b71Sopenharmony_ci UILabelButton* button2 = new UILabelButton(); 104e41f4b71Sopenharmony_ci button2->SetPosition(0, 0, g_ButtonW, g_ButtonH); 105e41f4b71Sopenharmony_ci button2->SetText("button2"); 106e41f4b71Sopenharmony_ci swipe->Add(button2); 107e41f4b71Sopenharmony_ci UILabelButton* button3 = new UILabelButton(); 108e41f4b71Sopenharmony_ci button3->SetPosition(0, 0, g_ButtonW, g_ButtonH); 109e41f4b71Sopenharmony_ci button3->SetText("button3"); 110e41f4b71Sopenharmony_ci swipe->Add(button3); 111e41f4b71Sopenharmony_ci ``` 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci2. Enable cyclic swiping for the **UISwipeView**. 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci ``` 116e41f4b71Sopenharmony_ci swipe->SetLoopState(true); 117e41f4b71Sopenharmony_ci ``` 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci3. Verify that the components are swiping horizontally and cyclically. 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci **Figure 2** Cyclic horizontal swiping effect of **UISwipeView**<a name="fig1533902042618"></a> 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci  125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci## GridLayout<a name="section46819199173"></a> 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci## When to Use<a name="section831618247294"></a> 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**GridLayout** provides the basic layout capability to set the number of grid rows and columns. Child components added via the **Add** function are automatically arranged after the **LayoutChildren\(\)** function is called. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci## Available APIs<a name="section597214622912"></a> 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**Table 2** Available functions in GridLayout 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci<a name="table109971146192913"></a> 138e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row9997104632911"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p119971146192917"><a name="p119971146192917"></a><a name="p119971146192917"></a>Function</p> 139e41f4b71Sopenharmony_ci</th> 140e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p7997204615291"><a name="p7997204615291"></a><a name="p7997204615291"></a>Description</p> 141e41f4b71Sopenharmony_ci</th> 142e41f4b71Sopenharmony_ci</tr> 143e41f4b71Sopenharmony_ci</thead> 144e41f4b71Sopenharmony_ci<tbody><tr id="row149976467292"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p159971046102912"><a name="p159971046102912"></a><a name="p159971046102912"></a>void SetRows(const uint16_t& rows)</p> 145e41f4b71Sopenharmony_ci</td> 146e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p14997846132913"><a name="p14997846132913"></a><a name="p14997846132913"></a>Sets the number of grid rows.</p> 147e41f4b71Sopenharmony_ci</td> 148e41f4b71Sopenharmony_ci</tr> 149e41f4b71Sopenharmony_ci<tr id="row299774652915"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p099744615296"><a name="p099744615296"></a><a name="p099744615296"></a>void SetCols(const uint16_t& cols)</p> 150e41f4b71Sopenharmony_ci</td> 151e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19971646142910"><a name="p19971646142910"></a><a name="p19971646142910"></a>Sets the number of grid columns.</p> 152e41f4b71Sopenharmony_ci</td> 153e41f4b71Sopenharmony_ci</tr> 154e41f4b71Sopenharmony_ci<tr id="row1199724616291"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p18997846202912"><a name="p18997846202912"></a><a name="p18997846202912"></a>void LayoutChildren(bool needInvalidate = false)</p> 155e41f4b71Sopenharmony_ci</td> 156e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1997174618291"><a name="p1997174618291"></a><a name="p1997174618291"></a>Lays out child components.</p> 157e41f4b71Sopenharmony_ci</td> 158e41f4b71Sopenharmony_ci</tr> 159e41f4b71Sopenharmony_ci</tbody> 160e41f4b71Sopenharmony_ci</table> 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci## How to Develop<a name="section1418253410306"></a> 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci1. Create a **GridLayout** instance and set its position and size. 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci ``` 167e41f4b71Sopenharmony_ci GridLayout* layout_ = new GridLayout(); 168e41f4b71Sopenharmony_ci layout_->SetPosition(0, g_y, HROIZONTAL_RESOLUTION, 200); 169e41f4b71Sopenharmony_ci layout_->SetLayoutDirection(LAYOUT_HOR); 170e41f4b71Sopenharmony_ci layout_->SetRows(2); 171e41f4b71Sopenharmony_ci layout_->SetCols(2); 172e41f4b71Sopenharmony_ci ``` 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci2. Create **UILabelButton** instances. 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci ``` 177e41f4b71Sopenharmony_ci UILabelButton* bt1 = new UILabelButton(); 178e41f4b71Sopenharmony_ci bt1->SetPosition(0,0,100,50); 179e41f4b71Sopenharmony_ci bt1->SetText("bt1"); 180e41f4b71Sopenharmony_ci UILabelButton* bt2 = new UILabelButton(); 181e41f4b71Sopenharmony_ci bt2->SetPosition(0, 0, 100, 50); 182e41f4b71Sopenharmony_ci bt2->SetText("bt2"); 183e41f4b71Sopenharmony_ci UILabelButton* bt3 = new UILabelButton(); 184e41f4b71Sopenharmony_ci bt3->SetPosition(0, 0, 100, 50); 185e41f4b71Sopenharmony_ci bt3->SetText("bt3"); 186e41f4b71Sopenharmony_ci UILabelButton* bt4 = new UILabelButton(); 187e41f4b71Sopenharmony_ci bt4->SetPosition(0, 0, 100, 50); 188e41f4b71Sopenharmony_ci bt4->SetText("bt4"); 189e41f4b71Sopenharmony_ci ``` 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci3. Add child components and call the **LayoutChildren\(\)** function. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci ``` 194e41f4b71Sopenharmony_ci layout_->Add(bt1); 195e41f4b71Sopenharmony_ci layout_->Add(bt2); 196e41f4b71Sopenharmony_ci layout_->Add(bt3); 197e41f4b71Sopenharmony_ci layout_->Add(bt4); 198e41f4b71Sopenharmony_ci layout_->LayoutChildren(); 199e41f4b71Sopenharmony_ci ``` 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci4. Verify the layout of buttons, as shown in the following figure. 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci **Figure 3** Setting a 2x2 grid and adding four buttons in a layout<a name="fig898719135314"></a> 204e41f4b71Sopenharmony_ci  205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci 207