Android 从小白到大拿之路——计算器的UI布局,虽然有些不完美
来源:互联网 发布:windows平板体验不好 编辑:程序博客网 时间:2024/04/27 16:23
昨晚在入睡前学习了android:layout_weight="1" ,更进一步了解了UI布局的一些小知识,然后经过早上的调试,终于把我想要实现的UI格局呈现出来了(目前只能在竖屏的情况下显示,而现成横屏的时候就不能正常显示了,我知道代码还是有问题 的,但是由于现在知识有限,不能很好的把握,大神勿喷!)
这是昨晚学习的文章:http://blog.csdn.net/luhuibo318/article/details/43463229
先把我要实现的布局给大家看看咯:
<pre name="code" class="html"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dp" tools:context="com.example.calculator.MainActivity" ><!-- 计算器的显示屏 --> <EditText android:layout_width="match_parent" android:layout_height="150dp" android:background="@drawable/get_shape" android:gravity="right|center_vertical" android:textColor="@color/color11" android:textSize="70dp" > </EditText> <!-- 显示屏的第一行设置 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/btnClear" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/select" android:text="c" android:textSize="42sp" /> <Button android:id="@+id/btnDelete" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Del" android:textSize="30sp" /> <Button android:id="@+id/btnDivide" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="÷" android:textSize="42sp" /> <Button android:id="@+id/btnMultiply" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="x" android:textSize="42sp" /> </LinearLayout> <!-- 显示屏的第2行设置 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" android:textSize="42sp" > <Button android:id="@+id/btnNum7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="7" android:textSize="42sp" /> <Button android:id="@+id/btnNum8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="8" android:textSize="42sp" /> <Button android:id="@+id/btnNum9" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="9" android:textSize="42sp" /> <Button android:id="@+id/btnSub" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="-" android:textSize="42sp" /> </LinearLayout> <!-- 显示屏的第3行设置 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" android:textSize="42sp" > <Button android:id="@+id/btnNum4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" android:textSize="42sp" /> <Button android:id="@+id/btnNum5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" android:textSize="42sp" /> <Button android:id="@+id/btnNum6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="6" android:textSize="42sp" /> <Button android:id="@+id/btnPlus" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="+" android:textSize="42sp" /> </LinearLayout> <!-- 显示屏的第4行设置 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" > <!-- 上面的 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/btnNum1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" android:textSize="42sp" /> <Button android:id="@+id/btnNum2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" android:textSize="42sp" /> <Button android:id="@+id/btnNum3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" android:textSize="42sp" /> </LinearLayout> <!-- 下面的 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/btnNum0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="right" android:text="0" android:textSize="42sp" /> <Button android:id="@+id/btnPoint" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:gravity="right" android:text="." android:textSize="42sp" /> </LinearLayout> </LinearLayout> <!-- 显示屏的第4行右边的“=”号 --> <Button android:id="@+id/btnResult" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="3" android:text="=" android:textSize="42sp" /> </LinearLayout></LinearLayout>
【思路】
1、总布局设置为Linear_layout , 方向orientation 设置为垂直 vertical
2、前三行的代码一样,设置为横向,添加4个按钮,并设置均匀分布<android:layout_weight="1">
3、最后一行再添加一个<Linear_layout>,然后再添加两个<Linear_layout>, 左边一个,右边“等号”单独一个,左边添加两个<Linear_layout>,上面的添加3个按钮,下面的添加两个按钮,就能够实现上面图片的布局
4、最后,需要注意的是在设置的时候需要调整各个按钮的大小和设置
0 0
- Android 从小白到大拿之路——计算器的UI布局,虽然有些不完美
- Android 从小白到大拿之路——计算器显示框的设置
- Android 从小白到大拿之路——简单计算器最终的实现
- Android 从小白到大拿之路——计算器_修改按钮样式
- Android 从小白到大拿之路——数字时钟和虚拟时钟的实现
- Android 从小白到大拿之路——登陆密码的明文显示
- Android 从小白到大拿之路——DrawerLayout抽屉的使用 (更新中)
- Android 从小白到大拿之路——Toast深入学习
- Android 从小白到大拿之路——ListView 简单学习
- Android 从小白到大拿之路——应用程序自动转屏
- Android 从小白到大拿之路——Intent学习
- Android 从小白到大拿之路——Intent+Action启动网页
- 基于keras的深度学习基本概念讲解——深度学习之从小白到入门
- 基于keras的深度学习基本概念讲解——深度学习之从小白到入门
- Easy ui 从小白到精通
- RS布局问题之块的不完美之完美
- Android开发计算器之布局
- Android——Tabel布局,计算器的实现
- Perl
- linux下批量修改文件及文件夹所有者及权限
- DOM解析XML字符串
- 使Upstart机制下的服务在系统启动时自动启动失效的三种方法+1
- Android xml 效果之 State List Drawable
- Android 从小白到大拿之路——计算器的UI布局,虽然有些不完美
- android自定义控件系列教程----继承ViewGroup实现带阻力效果的可回弹的SrollView
- Go 语言中的方法,接口和嵌入类型
- 基于事件的系统(Event-based System)的原型
- openwrt在mt7620a芯片上对外置PA的支持
- CInternetSession的简单使用
- ajax方法不进入success方法
- Android开发_微信分享功能
- Dubbo源码分析1