网格布局由GridLayout所代表,它是Android4.0新增的布局管理器
- GridLayout的基本设置:
android:columnCount=""
android:rowCount="" -
元素cell的基本控制
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_row=""
android:layout_rowSpan=""
android:layout_column=""
android:layout_columnSpan=""
制作一个简易计算器的界面:
计算器.PNG
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:alignmentMode="alignMargins"
android:columnCount="4"
android:rowCount="6">
<TextView
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_columnSpan="4"
android:background="#EE000000"
android:gravity="bottom|right"
android:padding="15dp"
android:text="1"
android:textColor="#FFFFFF"
android:textSize="48sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="C"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="/"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="*"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="删除"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="7"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="8"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="9"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="-"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="4"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="5"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="6"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="+"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="1"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="2"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="3"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowSpan="2"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg1"
android:text="="
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnSpan="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<Button
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/cal_bg"
android:text="."
android:textColor="#FFFFFF"
android:textSize="18sp" />
</GridLayout>
网友评论