AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hanqi.test6"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Activity1"> </activity> <activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" tools:context="com.hanqi.test6.MainActivity" android:orientation="vertical"><!--orientation改方向 vertical垂直--> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮一"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮二"
android:id="@+id/button2"
/> </LinearLayout>

MainActivity

package com.hanqi.test6;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取文件findViewById
Button button2 = (Button)findViewById(R.id.button2);
//设置setText
button2.setText("新按钮名");
}
}

Activity1

package com.hanqi.test6;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout; /**
* Created by Administrator on 2016/3/22.
*/
public class Activity1 extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //创建布局管理器 LinearLayout线性布局
LinearLayout linearLayout = new LinearLayout(this);
//setOrientation 布局方向 VERTICAL垂直
linearLayout.setOrientation(LinearLayout.VERTICAL);
//setLayoutParams属性 创建属性集合
linearLayout.setLayoutParams(
new DrawerLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)); Button button = new Button(this);
//设置显示的内容
button.setText("按钮二");
//setLayoutParams属性 创建属性集合
button.setLayoutParams(
new DrawerLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)); //把View放到布局里去 addView添加布局
linearLayout.addView(button);
button.setText("按钮三");
//setLayoutParams属性 创建属性集合
button.setLayoutParams(
new DrawerLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)); //把View放到布局里去 addView添加布局
linearLayout.addView(button);
//关联布局管理器 setContentView关联
setContentView(linearLayout);
}
}

UI和View 三种控制方式的更多相关文章

  1. UI自动化(selenium+python)之元素定位的三种等待方式

    前言 在UI自动化过程中,常遇到元素未找到,代码报错的情况.这种情况下,需要用等待wait. 在selenium中可以用到三种等待方式即sleep,implicitly_wait,WebDriverW ...

  2. AutoLayout的三种设置方式之——NSLayoutConstraint代码篇

    AutoLayout是从IOS 6开始苹果引入来取代autoresizing的新的布局技术,该技术有三种设置方式,等下我来为大家一一叙述一下. 在说三种设置方式前,我们先简单的说一下autolayou ...

  3. SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 SignalR 简单示例 通过三个DEMO学会SignalR的三种实现方式 SignalR推送框架两个项目永久连接通讯使用 SignalR 集线器简单实例2 用SignalR创建实时永久长连接异步网络应用程序

    SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论   异常汇总:http://www ...

  4. Django-多对多关系的三种创建方式-forms组件使用-cookie与session-08

    目录 表模型类多对多关系的三种创建方式 django forms 组件 登录功能手写推理过程 整段代码可以放过来 forms 组件使用 forms 后端定义规则并校验结果 forms 前端渲染标签组件 ...

  5. Action的三种实现方式,struts.xml配置的详细解释及其简单执行过程(二)

    勿以恶小而为之,勿以善小而不为--------------------------刘备 劝诸君,多行善事积福报,莫作恶 上一章简单介绍了Struts2的'两个蝴蝶飞,你好' (一),如果没有看过,请观 ...

  6. 通过三个DEMO学会SignalR的三种实现方式

    一.理解SignalR ASP .NET SignalR 是一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信(即:客户端(Web页面)和服务器端可以互相实时的通知消息 ...

  7. js的三种继承方式及其优缺点

    [转] 第一种,prototype的方式: //父类 function person(){ this.hair = 'black'; this.eye = 'black'; this.skin = ' ...

  8. spring ioc三种注入方式

    spring ioc三种注入方式 IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转 什么是控制反转? 控制反转是一种将组件依赖关系的创建和管理置于程序外部的技术. 由容 ...

  9. linux学习之centos(二):虚拟网络三种连接方式和SecureCRT的使用

    ---操作环境--- 虚拟机版本:VMware Workstation_10.0.3 Linux系统版本:CentOS_6.5(64位) 物理机系统版本:win10  一.虚拟网络三种连接方式 当在V ...

随机推荐

  1. [Android] Robotium手机自动化测试(仅需apk安装包版)——环境搭建 【转】

    Robotium的手机自动化测试,很多都是利用app源代码里的Id定义来开发自动化脚本.而在我开始要为项目中的app写自动化测试脚本的时 候,开发的环境还很不稳定,app也还处于开发的状态中,而且,在 ...

  2. 聚类分析K均值算法讲解

    聚类分析及K均值算法讲解 吴裕雄 当今信息大爆炸时代,公司企业.教育科学.医疗卫生.社会民生等领域每天都在产生大量的结构多样的数据.产生数据的方式更是多种多样,如各类的:摄像头.传感器.报表.海量网络 ...

  3. Scrapyd 的远程部署和监控

    1. 安装Scrapyd sudo pip3.6 install scrapyd # 安装scrapyd服务 sudo pip3.6 install scrapyd-client # 安装scrapy ...

  4. Java中for循环中的的try-catch

    异常处理 当for循环遇上try-catch @Test public void forThrow(){ final int size = 6; for (int i=0; i<size; i+ ...

  5. SPSS-生存分析

    生存分析 定义:一些医学事件所经历的时间:从开始观察到事件发生的时间,不是短期内可以明确判断的.针对这类生存资料的分析方法叫生存分析.生存分析的基本概念1.终点事件终点事件outcome event: ...

  6. 消息中间件MQ详解及四大MQ比较

    一.消息中间件相关知识 1.概述 消息队列已经逐渐成为企业IT系统内部通信的核心手段.它具有低耦合.可靠投递.广播.流量控制.最终一致性等一系列功能,成为异步RPC的主要手段之一.当今市面上有很多主流 ...

  7. css 鼠标选中内容背景色

    ::selection { background: rgba(32, 178, 170, .6); color: #ffffff; } ::-moz-selection { background: r ...

  8. HttpClient之EntityUtils对象

    最近在学习安卓并用thinkphp做后台,为了抵抗自己的烂记性,就在这里记录一下当我从tp后台获取到json串传到安卓客户端所用到的一个方法函数. EntityUtils对象是org.apache.h ...

  9. Using promises

    [Using promises] 过去,异步方法这样写: function successCallback(result) { console.log("It succeeded with ...

  10. 检查WMI协议是否通的

    在APM上的运行执行“wbemtest”,然后在上面的root\sivm前面加RPC不通的机器,先查WMI协议是否是通的