GridLayout 简单实例
来源:互联网 发布:mac如何下载qq游戏 编辑:程序博客网 时间:2024/05/16 14:12
代码部分:
src GridLayoutTest.java
package cn.com.gridlayouttest;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.widget.Button;import android.widget.GridLayout;public class GridLayoutTest extends Activity {GridLayout gridLayout;String[] chars=new String[]{"7","8","9","/","4","5","6","*","1","2","3","-",".","0","=","+"};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.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);}}}
清单文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.com.gridlayouttest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="cn.com.gridlayouttest.GridLayoutTest" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
布局文件 main.xml
<?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="match_parent" android:rowCount="6" android:columnCount="4" android:id="@+id/root"> <TextView 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" android:text="0" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_columnSpan="4" android:text="清除" /> </GridLayout>0 0
- GridLayout 简单实例
- GridLayout使用实例2
- java awt 简单示例 GridLayout
- GridLayout
- GridLayout
- gridlayout
- GridLayout
- GridLayout
- GridLayout
- gridlayout
- GridLayout
- GridLayout
- gridlayout
- GridLayout
- GridLayout
- GridLayout
- GridLayout
- GridLayout
- 自写jQuery插件,实现简单网页遮罩层/弹出层功能,兼容IE6、IE7
- OOP中的多态
- c++学习杂项
- 利用斯坦福主题模型工具(stanford TMT)做LDA
- cha
- GridLayout 简单实例
- C3P0是一个开放源代码的JDBC连接池
- 设计模式(一) 单例模式
- 下面是20个非常有用的Java程序片段,希望能对你有用。
- 阿里-聚石塔
- 你们有半数以上的人留下的是gmail而不是QQMail/Foxmail的电子邮件
- 大部分的CPU时间用于等待磁盘去读取数据
- tyvj 乘法游戏
- 《算法导论》笔记 第24章 24.4 差分约束与最短路径