1. 程式人生 > >Android實現計算器佈局(四種佈局方式)之TableLayout表格佈局

Android實現計算器佈局(四種佈局方式)之TableLayout表格佈局

表格佈局:tablelayout

table佈局不支援跨行跨列,所以主要佈局的思想就是表格巢狀

效果

計算器--table佈局
outline
計算器--table佈局
之前一直到不知道怎麼用表格實現計算器的佈局,查資料的時候也一直在考慮跨行跨列來實現,網上說table佈局不支援跨行跨列,早就該想到用表格的巢狀啦。用TableLayout佈局之後,才發現GridLayout有多麼好用

計算器--table

佈局原始碼

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" >
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow android:id="@+id/tableRow10" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="back" />
<Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="/" /> </TableRow> </TableLayout> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="*" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" /> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7" /> <Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="8" /> </TableRow> <TableRow android:id="@+id/tableRow5" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4" /> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5" /> </TableRow> </TableLayout> <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow6" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="9" /> </TableRow> <TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6" /> </TableRow> </TableLayout> <Button android:id="@+id/button11" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="+" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow8" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" /> <Button android:id="@+id/button13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" /> </TableRow> <TableRow android:id="@+id/tableRow9" android:layout_width="wrap_content" android:layout_height="wrap_content" > </TableRow> <Button android:id="@+id/button14" android:layout_width="match_parent" android:layout_height="match_parent" android:text="0" /> </TableLayout> <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow11" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3" /> </TableRow> <TableRow android:id="@+id/tableRow12" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="." /> </TableRow> </TableLayout> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="=" /> </TableRow> </TableLayout>

相關推薦

Android實現計算器佈局佈局方式TableLayout表格佈局

表格佈局:tablelayout table佈局不支援跨行跨列,所以主要佈局的思想就是表格巢狀 效果 outline 之前一直到不知道怎麼用表格實現計算器的佈局,查資料的時候也一直在考慮跨行跨列來實現,網上說table佈局不

Android實現開屏廣告廣點通SDK

一、註冊騰訊廣告賬號 註冊騰訊廣告聯盟賬號:http://e.qq.com/dev/index.html 二、新建廣告位 新建廣告位並下載SDK,記住自己的廣告位ID和應用ID。 三、接入SDK 1、解壓SDK,將jar檔案複製到libs目錄中,點選sync按鈕(as頂部工具欄)。在And

Android實現記賬本麻雀雖小,五臟俱全

1、在androidstudio上新建一個basic專案 2、在系統自動建立的content_main.xml檔案中新增listview,程式碼如下: <ListView android:id="@+id/lv_main" android:la

Selenium練習:百度搜索自動化指令碼定位方式

1. 實現百度搜索的自動化測試指令碼,需滿足要求如下: 1)瀏覽器至少選擇兩種(火狐+chrome/ie),關鍵詞為“福哥雜記 CSDN”; 2)指令碼檔案命名為“{組名}_{姓名}_百度搜索_{瀏覽器}_{指令碼序號}.py” 3)搜尋框和“百度一下”元素的定位方式,至少

遠程調試部署在Tomcat中的應用服務2配置方式

tab jdk1 exe java ee center 右鍵 eclipse 找到 platform 遠程調試部署在Tomcat中的應用服務(tomcat 遠程debug 配置文件) 方法一(編輯catalina.bat) 1. D:\iVMS_Platform\bin\a

struts2封裝客戶端請求數據3封裝方式

空指針異常 必須 nis png pri pan this drive .cn 長話短說,直接進入主題. 1.屬性驅動 action的屬性名稱必須和jsp輸入項的name屬性保持一致; 必須要在action類中提供該屬性的set方法,但有時候會出錯,為了保險起見,我們把g

1.4socket服務器打印信息的不同方式(

span 綁定 col tip ner 1.4 一次 +++ soc 方式一 socker 服務器 # -*- coding: utf-8 -*- import sys,os,multiprocessing from socket import * serverHost

Android 資料持久化技術即資料儲存方式

在討論資料持久化技術之前我們先了解幾個概念? 什麼是瞬時資料:儲存在記憶體當中,有可能會因為程式的關閉或其他原因導致記憶體被收回而丟失的資料。   為什麼採用資料持久化技術:為了保證關鍵資料在程式退出時不被丟失。   什麼是資料持久化技術:將記憶體中的瞬時資料

spring+redis自主實現分散式session非spring-session方式

背景:最近對一個老專案進行改造,使其支援多機部署,其中最關鍵的一點就是實現多機session共享。專案有多老呢,jdk版本是1.6,spring版本是3.2,jedis版本是2.2。 1.方案的確定 接到這專案任務後,理所當然地google了,一搜索,發現結果分為兩大類: tomcat的session管

設定Windows防火牆以允許被ICMP Ping配置方式

本文由荒原之夢原創,原文連結:http://zhaokaifeng.com/?p=1119 背景與目的 Ping測試常被用於測試網路中兩臺主機之間是否互相連通,但是,大多數Windows作業系統(包括桌面版和伺服器版)預設都是隻允許ping其他主機而不允許其他主機ping自己。下

java筆記--關於執行緒同步7同步方式

關於執行緒同步(7種方式) 為何要使用同步?     java允許多執行緒併發控制,當多個執行緒同時操作一個可共享的資源變數時(如資料的增刪改查),      將會導致資料不準確,相互之間產生衝突,因此加入同步鎖以避免在該執行緒沒有完成操作之前,被其他執行緒的呼叫,      從而保證了該變數的唯一性

佈局LayoutsTableLayout表格佈局

TableLayout表格佈局   TableLayout是指將子元素的位置分配到行或列中。Android的一個TableLayout有許多TableRow組成,每一個TableRow都會定義一個

關於線程同步7同步方式

初始 就是 允許 public 底層 多線程並發 unlock 同步機制 獲取 為何要使用同步? java允許多線程並發控制,當多個線程同時操作一個可共享的資源變量時(如數據的增刪改查), 將會導致數據不準確,相互之間產生沖突,因此加入同步鎖以避免在該線程沒有完成操

項目一:第十二天 1、常見權限控制方式 2、基於shiro提供url攔截方式驗證權限 3、在realm中授權 5、總結驗證權限方式 6、用戶註銷7、基於treegrid實現菜單展示

eal 重復數 規則 認證通過 delete get 數據庫 filter 登陸 1 課程計劃 1、 常見權限控制方式 2、 基於shiro提供url攔截方式驗證權限 3、 在realm中授權 4、 基於shiro提供註解方式驗證權限 5、 總結驗證權限方式(四種) 6、

Android底部導航欄的實現

現在大多數App都會用到底部導航欄,比如常見的聊天工具QQ、微信,購物App等等,有了底部導航欄,使用者可以隨時切換介面,檢視不同的內容。它的實現方式也很多,以前大多使用TabHost來實現,但是現在我們有很多更好的選擇。 使用LinearLayout +

Android自動化測試初探: 模擬鍵盤滑鼠事件Socket+Instrumentation實現

通過Socket + Instrumentation實現模擬鍵盤滑鼠事件主要通過以下三個部分組成:   *   Socket程式設計:實現PC和Emulator通訊,並進行迴圈監聽   *   Service服務:將Socket的監聽程式放在Service中,從而達到

二叉樹遍歷方式、迭代及遞迴的實現

二叉樹的常見遍歷方式主要有前序,中序和後序,以及層次遍歷(從上到下,從左到右)四種方法。 前、中、後遍歷分別順序如下: 分別通過遞迴和迴圈的方式實現(Python): # -*- coding:utf-8 -*- class TreeNode: def __

EXT.NET複雜佈局——系統首頁設計

此篇為EXT.NET系列終結篇。希望此係列能夠對大家有所幫助。 首頁JS函式介紹 使然使用了Ext.NET,但是JavaScript的地位還是舉足輕重的。 1.新增選項卡 1: var addTab = function (id, url, title) { 2:

android實現計算器慕課網視訊教學

網址:http://www.imooc.com/video/3071 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://s

CSS實現邊框佈局百度前端筆試

主要思想為:先實現大的正方形邊框,在邊框前實現黑底三角形,再覆蓋一個白底三角形。 主要用border-left-color實現三角形,left則三角形頂點向右,right則三角形頂點向左。 <!DOCTYPE html> <html> <h