In Android 4.0 (API 14), a completely new component GridLayout, which inherits from LinearLayout, is used for the layout of the Web format.
In some ways, GridLayout is similar to Tablelayout and the GridView. His strong point is that you can specify that each cell "spans" several cells or "vertically" several cells, which is similar to the <table> tags in HTML.
Several important properties of GridLayout:
RowCount: Number of rows
ColumnCount: Number of columns
GridLayout's child view will be able to apply attributes:
Layout_rowspan: vertically across several cells
Layout_columnspan: horizontally across several cells
Also, GridLayout's child view can not specify Layout_width and Layout_height (similar to tablelayout)
Using GridLayout, you can easily develop a calculator-like page that simplifies code, simplifies nesting levels, improves performance, and adapts to better performance than using LinearLayout.
:
Layout code:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:padding=" 8DP "android:layout_width=" Match_parent "Android:layo ut_height= "Match_parent" > <textview android:layout_width= "wrap_content" android:layout_height= "wrap _content "android:textsize=" 18sp "android:text=" calculator "/> <gridlayout android:layout_width=" WR Ap_content "android:layout_height=" Wrap_content "android:rowcount=" 5 "android:columncount=" 4 " android:layout_margin= "4DP" > <button android:text= "C"/> <button android:text= "Del"/> <button android:text= "/"/> <button android:text= "x"/> <button android:text= "7"/> <button android:text= "8"/> <button android:text= "9"/> <button android:text= "-"/> <button android:text= "4"/> <button android:text= "5"/> <button android:text= "6"/> <button android:text= "+"/> <button android:text= "1"/> <button android:text= "2"/> <button android:text= "3"/> <button android:text= "=" android:layout_gravity= "Fill" android:layout_rowspan= "2"/& Gt <button android:text= "0" android:layout_gravity= "Fill" android:layout_columnspan= "2"/ > <button android:text= "."/> </GridLayout></LinearLayout>
Android 4.0 New components: GridLayout detailed