Android 的计算器界面设计
来源:互联网 发布:债券代持 知乎 编辑:程序博客网 时间:2024/06/12 04:26
第一步:在Main_xml文件中布局设计代码:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:rowCount="6" android:columnCount="4" android:id="@+id/root" > <TextView android:text="0" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_columnSpan="4" android:textSize="50sp" android:layout_marginLeft="4px" android:layout_marginRight="4px" android:padding="5px" android:layout_gravity="right" android:background="#eee" android:textColor="#000" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_columnSpan="4" android:text="清除"/></GridLayout>
第二步,在MainActivity中的代码:
package com.example.yangjian.learngridlayout;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Gravity;import android.view.Menu;import android.view.MenuItem;import android.widget.Button;import android.widget.GridLayout;public class MainActivity extends ActionBarActivity { GridLayout gridLayout; String[] chars = new String[]{ "7", "8", "9", "÷", "4", "5", "6", "×", "3", "2", "1", "-", ".", "0", "=", "+" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gridLayout = (GridLayout) findViewById(R.id.root); for(int i=0; i<chars.length; i++) { Button bn = new Button(this); bn.setText(chars[i]); bn.setTextSize(40); GridLayout.Spec rowSpec = GridLayout.spec(i / 4 + 2); GridLayout.Spec columnSpec = GridLayout.spec(i % 4); GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpec, columnSpec); params.setGravity(Gravity.FILL); gridLayout.addView(bn, params); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
0 0
- Android 的计算器界面设计
- android线性布局之计算器界面设计
- Android的界面设计规范
- Android的界面设计规范
- Android基础综合案例(七)《简易计算器UI界面设计》
- 关于Android的一些界面设计
- DroidDraw---Android的界面设计工具
- DroidDraw---Android的界面设计工具
- Android仿Metro的界面设计
- Android界面设计的一点体会
- android界面设计的几个良好习惯
- Android的app界面设计规范
- 网格布局(计算器界面设计)
- 7.28 网页计算器基本界面设计
- 我的Android计算器
- android 简易的计算器
- 简单的android计算器
- Android 计算器的开发
- Android解决ScrollView嵌套ListView滑动冲突问题
- 从优化到再优化,最长公共子串
- 从优化到再优化,最长公共子串
- TCP协议中的三次握手和四次挥手(图解)
- 从优化到再优化,最长公共子串
- Android 的计算器界面设计
- GeForce GTX 980 Ti+Ubuntu15.04+cuda7.0+caffe
- 高仿百度传课iOS版,版本号2.4.1.2
- 从优化到再优化,最长公共子串
- 9. Document getElementsByName() 方法
- HDU 1312:Red and Black【递归】
- 南邮 OJ 1031 建筑群最长坡值
- 从优化到再优化,最长公共子串
- cocos2d-x从新建到打包成apk