【Android】使用LinearLayout实现计算器效果
2013-11-06 16:27
357 查看
Ubuntu下截屏花了好长时间,最后设置的快捷键为Crtl+Alt+A
这个效果实际上是这么做的。
首先整个页面分为6个水平线性布局,最后一个占两行。外面那个大布局是垂直排列。
难点在于最后一个,将其分为两个水平线性布局,第一个又包含了两个布局(垂直排列),第二个就是等号按钮。
代码如下:
这个效果实际上是这么做的。
首先整个页面分为6个水平线性布局,最后一个占两行。外面那个大布局是垂直排列。
难点在于最后一个,将其分为两个水平线性布局,第一个又包含了两个布局(垂直排列),第二个就是等号按钮。
代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" android:orientation="vertical" > <!-- 布局可以嵌套布局 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/msg" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="mc" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="m+" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="m-" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="mr" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="C" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="+/-" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="/" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="*" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="7" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="8" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="9" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="-" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="4" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="5" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="6" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="+" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="3" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="2" android:text="0" /> <Button android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="1" android:text="." /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" 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="=" /> </LinearLayout> </LinearLayout> </LinearLayout>
相关文章推荐
- 使用线性布局LinearLayout实现类似计算器的效果
- Android中如何使用ViewPager实现类似laucher左右拖动效果
- Android照片墙加强版,使用ViewPager实现画廊效果
- android开发之滑动效果实现图片浏览_ViewFilpper的使用
- android开发之&使用ViewPager加gridView实现菜单按钮分页滑动(类似QQ表情选择翻页效果)
- Android时间轴(Timeline)效果的实现(使用RecyclerView)
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- android 使用SurfaceView实现小球高处落下并弹起的效果
- Android使用GridView实现横向滚动效果
- Android使用动画实现微信扫描线效果
- android使用TextView实现文字的跑马灯效果
- android 使用OPENGL ES实现纹理拉伸效果-纹理映射基础
- 【转】Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- Android 使用shape来实现界面效果
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- android 使用GridView实现Gallery的效果,并且从最左边开始
- Android使用systembartint库实现沉浸式状态栏效果
- android开发(46) 使用 textview实现文字的阴影效果,浮雕效果
- [Android] PorterDuff使用实例----实现新浪微博图片下载效果
- Android 使用CoordinatorLayout实现滚动标题栏效果的实例