線性佈局LinearLayout

来源:http://www.cnblogs.com/Renyi-Fan/archive/2017/08/02/7275933.html
-Advertisement-
Play Games

線性佈局LinearLayout 一、簡介 LinearLayout是一種線型的佈局方式。LinearLayout佈局容器內的組件一個挨著一個地排列起來:不僅可以控制個組件橫向排列,也可控制各組件縱向排列。通過orientation屬性設置線性排列的方向是垂直(vertical)還是縱向(horiz ...


線性佈局LinearLayout

一、簡介

LinearLayout是一種線型的佈局方式。LinearLayout佈局容器內的組件一個挨著一個地排列起來:不僅可以控制個組件橫向排列,也可控制各組件縱向排列。通過orientation屬性設置線性排列的方向是垂直(vertical)還是縱向(horizontal)。 

 

線性佈局實例

 

二、代碼實例

效果圖:

結構

 

代碼:

 /Test_LinearLayout/res/layout/activity_main.xml

android:layout_weight="4"
權重
android:gravity="bottom|right"
字體靠右下
android:orientation="vertical" >
垂直佈局

xmlns:android="http://schemas.android.com/apk/res/android"
命名空間

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:layout_width="match_parent"
  4     android:layout_height="match_parent"
  5     android:orientation="vertical" >
  6     <!-- 輸入框 -->
  7     <EditText
  8         android:id="@+id/editText_input"
  9         android:layout_width="match_parent" 
 10         android:layout_height="wrap_content"
 11         android:gravity="bottom|right"
 12        
 13         android:text=""
 14         android:layout_weight="4"
 15         android:textSize="@dimen/fontSize_num"
 16         />
 17     
 18     <!-- 中間按鍵區 -->
 19     <LinearLayout
 20         android:layout_width="match_parent"
 21         android:layout_height="wrap_content"
 22         android:orientation="vertical"
 23         android:layout_weight="12"
 24         
 25         >
 26         <!-- 中間按鍵區:第一排 -->
 27         <LinearLayout
 28               android:layout_width="match_parent"
 29                  android:layout_height="wrap_content"
 30                  android:orientation="horizontal"
 31                  android:layout_weight="1"
 32                  
 33             >
 34             <Button
 35                 android:id="@+id/btn_num7"
 36                 android:layout_width="wrap_content"
 37                 android:layout_height="wrap_content"
 38                 android:text="7"
 39                 android:layout_weight="2"
 40                 android:textSize="@dimen/fontSize_num"
 41                 />
 42             <Button
 43                 android:id="@+id/btn_num8"
 44                 android:layout_width="wrap_content"
 45                 android:layout_height="wrap_content"
 46                 android:text="8"
 47                 android:layout_weight="2"
 48                 android:textSize="@dimen/fontSize_num"
 49                 />
 50             <Button
 51                 android:id="@+id/btn_num9"
 52                 android:layout_width="wrap_content"
 53                 android:layout_height="wrap_content"
 54                 android:text="9"
 55                 android:layout_weight="2"
 56                 android:textSize="@dimen/fontSize_num"
 57                 />
 58             <Button
 59                 android:id="@+id/btn_symbol_divide"
 60                 android:layout_width="wrap_content"
 61                 android:layout_height="wrap_content"
 62                 android:text="/"
 63                 android:layout_weight="2"
 64                 android:textSize="@dimen/fontSize_num"
 65                 />
 66         </LinearLayout>
 67         
 68        <!-- 中間按鍵區:第二排 -->
 69         <LinearLayout
 70               android:layout_width="match_parent"
 71                  android:layout_height="wrap_content"
 72                  android:orientation="horizontal"
 73                  android:layout_weight="1"
 74                  android:textSize="@dimen/fontSize_num"
 75             >
 76             <Button
 77                 android:id="@+id/btn_num4"
 78                 android:layout_width="wrap_content"
 79                 android:layout_height="wrap_content"
 80                 android:text="4"
 81                 android:layout_weight="2"
 82                 android:textSize="@dimen/fontSize_num"
 83                 />
 84             <Button
 85                 android:id="@+id/btn_num5"
 86                 android:layout_width="wrap_content"
 87                 android:layout_height="wrap_content"
 88                 android:text="5"
 89                 android:layout_weight="2"
 90                 android:textSize="@dimen/fontSize_num"
 91                 />
 92             <Button
 93                 android:id="@+id/btn_num6"
 94                 android:layout_width="wrap_content"
 95                 android:layout_height="wrap_content"
 96                 android:text="6"
 97                 android:layout_weight="2"
 98                 android:textSize="@dimen/fontSize_num"
 99                 />
100             <Button
101                 android:id="@+id/btn_symbol_multiply"
102                 android:layout_width="wrap_content"
103                 android:layout_height="wrap_content"
104                 android:text="*"
105                 android:layout_weight="2"
106                 android:textSize="@dimen/fontSize_num"
107                 />
108         </LinearLayout>
109        
110         <!-- 中間按鍵區:第三排 -->
111         <LinearLayout
112               android:layout_width="match_parent"
113                  android:layout_height="wrap_content"
114                  android:orientation="horizontal"
115                  android:layout_weight="1"
116                  android:textSize="@dimen/fontSize_num"
117             >
118             <Button
119                 android:id="@+id/btn_num1"
120                 android:layout_width="wrap_content"
121                 android:layout_height="wrap_content"
122                 android:text="1"
123                 android:layout_weight="2"
124                 android:textSize="@dimen/fontSize_num"
125                 />
126             <Button
127                 android:id="@+id/btn_num2"
128                 android:layout_width="wrap_content"
129                 android:layout_height="wrap_content"
130                 android:text="2"
131                 android:layout_weight="2"
132                 android:textSize="@dimen/fontSize_num"
133                 />
134             <Button
135                 android:id="@+id/btn_num3"
136                 android:layout_width="wrap_content"
137                 android:layout_height="wrap_content"
138                 android:text="3"
139                 android:layout_weight="2"
140                 android:textSize="@dimen/fontSize_num"
141                 />
142             <Button
143                 android:id="@+id/btn_symbol_subtract"
144                 android:layout_width="wrap_content"
145                 android:layout_height="wrap_content"
146                 android:text="-"
147                 android:layout_weight="2"
148                 android:textSize="@dimen/fontSize_num"
149                 />
150         </LinearLayout>
151      
152         <!-- 中間按鍵區:第四排 -->
153         <LinearLayout
154               android:layout_width="match_parent"
155                  android:layout_height="wrap_content"
156                  android:orientation="horizontal"
157                  android:layout_weight="1"
158             >
159             <Button
160                 android:id="@+id/btn_num0"
161                 android:layout_width="wrap_content"
162                 android:layout_height="wrap_content"
163                 android:text="0"
164                 android:layout_weight="2"
165                 android:textSize="@dimen/fontSize_num"
166                 />
167             <Button
168                 android:id="@+id/btn_symbol_point"
169                 android:layout_width="wrap_content"
170                 android:layout_height="wrap_content"
171                 android:text="."
172                 android:layout_weight="2"
173                 android:textSize="@dimen/fontSize_num"
174                 />
175             <Button
176                 android:id="@+id/btn_symbol_add"
177                 android:layout_width="wrap_content"
178                 android:layout_height="wrap_content"
179                 android:text="+"
180                 android:layout_weight="2"
181                 android:textSize="@dimen/fontSize_num"
182                 />
183             <Button
184                 android:id="@+id/btn_symbol_equal"
185                 android:layout_width="wrap_content"
186                 android:layout_height="wrap_content"
187                 android:text="="
188                 android:layout_weight="2"
189                 android:textSize="@dimen/fontSize_num"
190                 />
191         </LinearLayout>
192         
193         
194     </LinearLayout>
195     
196     <!-- 最下麵clear區 -->
197    <Button
198         android:id="@+id/btn_clear"
199         android:layout_width="match_parent" 
200         android:layout_height="wrap_content"
201         android:text="clear"
202         android:layout_weight="2"
203         android:textSize="@dimen/fontSize_num"
204         />
205 
206 </LinearLayout>
207  

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.內容在一屏內顯示的,採用了(內容框)上下左右居中的辦法,裡面的內容絕對於這個內容框定位.這樣一來,在不同大小屏中,內容總是在中間,看起來較正常 2.長,寬,LEFT,TOP,RIGHT,BOTTOM都採用了REM,並且HTML的FONT-SIZE設置的是100PX一是覺得計算方便,二是如果設為1 ...
  • sass文件轉css時註釋雖然支持中文,但是出現亂碼的解決方法 Scss 註釋中文報錯問題(windows系統, 已解決)找到ruby的安裝目錄,裡面也有sass模塊,類似這樣樣的路徑:F:\Program Files (x86)\Ruby24-x64\lib\ruby\gems\2.4.0\gem ...
  • 表格佈局tabelLayout 一、簡介 二、實例 ...
  • 框架佈局FrameLayout 一、簡介 二、代碼實例 結果圖: 代碼: 需要註意的代碼: framelayoutfry2.MainActivity /Test_FrameLayout/res/layout/activity_main.xml ...
  • Windows下的Android遠程桌面助手(Android Remote Displayer and Controller),增加了錄製視頻功能,突破了Android原生180S的限制。 ...
  • 程式猿是否應該接私活? 我大約從去年 11 月份開始接私活做,到目前為止也有大半年了。自己在這大半年的時間里,也學習了很多,在此記錄一下這大半年來的感受以及一些不成熟的建議。 在我看來,在你又打算接私活的時候,你應該考慮以下幾個問題 時間是否充裕? 個人認為這個問題非常重要,如果時間不夠充裕的話,接 ...
  • Coundn't load memtrack module (No such file or directory) 去仔細看日誌,是包名有問題 一、出現癥狀 提示找logcat logcat裡面發現Coundn't load memtrack module (No such file or dire ...
  • JSX並不是一門新的開發語言,而是Facebook提出的語法方案:一種可以在JavaScript代碼中直接書寫HTML標簽的語法糖,所以,JSX本質上還是JavaScript語言。 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...