LinearLayout和GridLayout实现计算器

2025-05-07 22:12:34

使用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实现计算器
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢