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. setting 常用配置

    一,保存logging 信息 # 保存log信息的文件名 LOG_LEVEL = "INFO" LOG_STDOUT = True LOG_ENCODING = 'utf-8' # ...

  2. 模块移除 命令rmmod 的实现

    // rmmod.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include < ...

  3. Latex公式示范

    \(A_\alpha(x)\)      \(\qquad\)      \(a^2+b^2=c^2 \)      \(\qquad\)      \(\sum\limits_{m=0}^\inft ...

  4. html5新增标签做基本布局

    结构标记 ***** 做布局 1.<header>元素 <header></header> ==> <div id="header" ...

  5. ES2015 import & export

    [ES2015 import] The import statement is used to import functions, objects or primitives that have be ...

  6. day21 xml模块 ATM+购物车

    1. xml模块 <father name="jack"> # 属性的值必须加双引号 <son> 标签的关闭顺序,与开启顺序相反, 最先开启的最后关闭,最后 ...

  7. Appium1.6 GUI界面介绍

    Appium1.6安装详见随笔:http://www.cnblogs.com/meitian/p/7360017.html   下面具体介绍一下GUI界面 1.appium server配置页面 2. ...

  8. FileItem类的常用方法(关于文件上传的)

    1.boolean  isFormField().isFormField方法用来判断FileItem对象里面封装的数据是一个普通文本表单字段,还是一个文件表单字段.如果是普通文本表单字段,返回一个tr ...

  9. centos 7.2 安装域名服务器(bind9.9 集群--主从架构),私有域名服务器+缓存

    1.安装组件 yum install bind bind-utils -y 2.启动域名服务 service named start chkconfig named on ss -unlt |grep ...

  10. axaj 的回调

    //为了动态生成表格获取数据用ajax获取servlet回调数据 <script> $.ajax({ url = "servlet地址", type : "p ...