惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
GbyAI
GbyAI
爱范儿
爱范儿
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
M
MIT News - Artificial intelligence
量子位
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
罗磊的独立博客
F
Fortinet All Blogs
美团技术团队
博客园_首页
博客园 - 【当耐特】
L
LangChain Blog
月光博客
月光博客
腾讯CDC
The Cloudflare Blog
D
Docker
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - gwazy

wifi zigbee 蓝牙区别 easyui textbox 获取焦点 easyUI 异步加载树 sql 有条件计数 easyui combox 手动添加项 只有设置了 name 属性的表单元素才能在提交表单时传递它们的值 除湿方法 android 页面跳转,数据回传 android studio 乱码 android studio 工具 android 开发 简单的页面布局 android sdk 重装windows7企业版时提示“安装程序无法创建新的系统分区,也无法定位现有系统 csdn 泄露用户密码害人不浅啊。 PoolMon 使用 固态硬盘相关知识 android 平台搭建 win8 中使用第三方无线网卡出现无线连接受限解决办法 iis 故障导致网站无法访问
gridlaylout 简单布局
gwazy · 2015-04-29 · via 博客园 - gwazy
package com.example.gridlayout;


import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.Button;
import android.widget.GridLayout;


public class MainGrid extends Activity {
    GridLayout grd;
    String[] chas=new String[]
            {
              "7","8","9","*"
              ,"4","5","6","/"
              ,"1","2","3","+"
              ,"0",".","=","-"
            
            };
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main_grid);
        grd=(GridLayout)findViewById(R.id.root);
        for(int i=0;i<chas.length;i++)
        {
            Button bt=new Button(this);
             bt.setText(chas[i]);
             bt.setTextSize(40);
             bt.setHeight(200);
                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);        
                grd.addView(bt , params);

        }
    }
}
<?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"
    >
<!-- 定义一个横跨4列的文本框,
并设置该文本框的前景色、背景色等属性  -->
<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"/>
<!-- 定义一个横跨4列的按钮 -->
<Button 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_columnSpan="4"
    android:text="清除"/>
</GridLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.gridlayout"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainGrid"
            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>