LinearLayout和GridLayout实现计算器

 时间:2025-01-06 18:59:49

使用LinearLayout、GridLayout布局实现计算器界面,

工具/原料

eclipse代码编辑器

sdk

adt

GridLayout实现计算器布局

1、<?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="wrap_content" android:layout_margin="30dp" android:columnCount="4" > <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn1" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn2" /> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn3" /> <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_rowSpan="2" android:layout_gravity="fill" android:text="btn4" /> <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn5" /> <Button android:id="@+id/btn6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn6" /> <Button android:id="@+id/btn7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn7" /> <Button android:id="@+id/btn8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_columnSpan="2" android:layout_gravity="fill" android:text="btn8" /> <Button android:id="@+id/btn9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_columnSpan="2" android:layout_gravity="fill" android:text="btn9" /></GridLayout>

LinearLayout和GridLayout实现计算器

LinearLayout布局实现计算器界面

1、<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="75dp" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="1" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="2" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="3" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="/" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="75dp" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="4" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="5" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="6" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="*" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="75dp" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="7" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="8" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="9" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="-" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="150dp" android:orientation="horizontal" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="0" /> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2" android:text="." /> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="=" /> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3" android:text="+" /> </LinearLayout></LinearLayout>

LinearLayout和GridLayout实现计算器
  • 茶与菜品的优雅搭配——茶香煎鳕鱼
  • 智能运动手表APP开发
  • 突然患上了鼻炎怎么办?
  • 游泳镜有雾气怎么解决
  • Windows 系统漏洞产生的原因有哪些?
  • 热门搜索
    信服的近义词 掩饰的近义词 嘴角长疱疹怎么办 头有点晕是怎么回事 烟花烫发型 周杰伦发型 奇幻的近义词 日光性皮炎怎么办 五谷磨房的东西怎么样 小肚子坠疼怎么回事