使用表格布局实现界面计算器按钮

来源:互联网 发布:武汉有mac专柜吗 编辑:程序博客网 时间:2024/05/09 11:38
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="0,1,2,3"//设置可调宽度的列的序号,从0开始
    tools:context=".Addressbook" >


<TableRow>
   <Button 
       android:layout_width="wrap_content"//有内容设置宽度
       android:layout_height="wrap_content"//有内容设置高度
       android:text="C"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="---"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="/"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="*"
       />
</TableRow>
<TableRow>
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="7"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="8"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="9"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="-"
       />
</TableRow>
<TableRow>
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="4"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="5"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="6"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="+"
       />
</TableRow>
<TableRow>
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="1"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="2"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="3"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="."
       />
</TableRow>
<TableRow>
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="( )"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="0"
       />
   <Button 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_span="2"//合并2列
       android:text="="
       />
  
</TableRow>
</TableLayout>
0 0
原创粉丝点击