布局文件

android:layout_width="match_parent"

android:layout_height="match_parent"

android:rowCount="6"

android:columnCount="4"

android:id="@+id/grid">

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="@android:color/white"

android:textColor="@android:color/black"

android:text="0"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_columnSpan="4"

android:textSize="40sp"

android:text="清除"/>

源码

GridLayoutgridLayout;

String[]chars=newString[]{

"7","8","9","+",

"4","5","6","-",

"1","2","3","*",

".","0","=","/",

};

@Override

protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

gridLayout= (GridLayout)findViewById(R.id.grid);

for(inti =0;i

Button bn =newButton(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 =newGridLayout.LayoutParams(rowSpec,columnSpec);

gridLayout.addView(bn,params);

}

}

更多相关文章

  1. android .xml文件 布局文件
  2. 50个Android开发人员必备UI效果源码[转载]
  3. [Android]Android高级UI开发系列教程(二) - Android绘制教程
  4. android中xml文件注意事项
  5. Android: 向最强看齐, 反编译 愤怒的小鸟.apk
  6. Android: 向最强看齐, 反编译 愤怒的小鸟.apk
  7. Android: 向最强看齐, 反编译 愤怒的小鸟.apk
  8. Android电池
  9. webpack 配置文件webpack.config.js

随机推荐

  1. Linux学习之linux的find命令如何使用?
  2. python数据类型的强制转换
  3. 动画:面试必刷之对称的二叉树
  4. 字符串处理函数
  5. 就说一件事!
  6. Spring Cloud分布式微服务实战(养成应对复
  7. 自学系列 | 就谈自学方法!
  8. 动画:「变量提升」引发的一场"血"案 !
  9. 动画:面试必刷之二叉树的镜像
  10. 标识符的认识