Android GridLayout使用案例详解

  <?xml version="1.0" encoding="utf-8"?>

  

  xmlns:android="http://schemas.android.com/apk/res/android"

  xmlns:app="http://schemas.android.com/apk/res-auto"

  xmlns:tools="http://schemas.android.com/tools"

  android:id="@+id/grid_layout"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:background="#ece7e7"

  app:alignmentMode="alignBounds"

  app:columnCount="4"

  app:orientation="horizontal"

  app:rowCount="5"

  app:useDefaultMargins="false"

  tools:context="com.strivestay.gridlayoutdemo.MainActivity">

  

  

  android:gravity="right|bottom"

  android:text="0"

  app:layout_columnSpan="4"

  app:layout_rowWeight="3"

  app:layout_columnWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="AC"

  android:textColor="#f68904"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="退格"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="/"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="*"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="7"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="8"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="9"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="—"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="4"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="5"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="6"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="+"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="1"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="2"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="3"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#f68904"

  android:gravity="center"

  android:text="="

  android:textColor="#ffffff"

  app:layout_columnWeight="1"

  app:layout_rowSpan="2"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="%"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="0"

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>

  

  android:layout_margin="1dp"

  android:background="#ffffff"

  android:gravity="center"

  android:text="."

  app:layout_columnWeight="1"

  app:layout_rowWeight="1"/>