Android GridLayout簡介,以計算機為例

來源:互聯網
上載者:User

標籤:android



《Android GridLayout簡介,以計算機為例》

Android GridLayout預設從左往右水平布局元素。可以通過設定屬性:android:orientation=,控制子項目布局的方向為水平還是垂直。

GridLayout的屬性 android:layout_row 和 android:layout_column 設定常數值則指定GridLayout顯示的行列數。

設定 android:layout_rowSpan 或者 android:layout_columnSpan 常數值,且同時設定android:layout_gravity="fill",則該元素將跨界佔滿指定的行列。

以一個簡單的計算機布局為例加以說明,該計算機僅僅通過一個布局檔案即可實現,下面就是一個使用Android GridLayout布局實現的計算機如下:


上面用Android GridLayout實現的計算機XML布局檔案完整代碼:

<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:columnCount="4"    android:orientation="horizontal"    android:rowCount="5" >    <Button        android:id="@+id/one"        android:text="1" />    <Button        android:id="@+id/two"        android:text="2" />    <Button        android:id="@+id/three"        android:text="3" />    <Button        android:id="@+id/devide"        android:text="/" />    <Button        android:id="@+id/four"        android:text="4" />    <Button        android:id="@+id/five"        android:text="5" />    <Button        android:id="@+id/six"        android:text="6" />    <Button        android:id="@+id/multiply"        android:text="×" />    <Button        android:id="@+id/seven"        android:text="7" />    <Button        android:id="@+id/eight"        android:text="8" />    <Button        android:id="@+id/nine"        android:text="9" />    <Button        android:id="@+id/minus"        android:text="-" />    <Button        android:id="@+id/zero"        android:layout_columnSpan="2"        android:layout_gravity="fill"        android:text="0" />    <Button        android:id="@+id/point"        android:text="." />    <Button        android:id="@+id/plus"        android:layout_gravity="fill"        android:layout_rowSpan="2"        android:text="+" />    <Button        android:id="@+id/equal"        android:layout_columnSpan="3"        android:layout_gravity="fill"        android:text="=" /></GridLayout>

Android GridLayout簡介,以計算機為例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.