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. VC++ 自定义控件的建立及使用方法

    一.VC++定义自定义控件与delphi,VB有些差异. delphi,vb在 file-new-other中建立.vc++在工具栏中就有自定义控件,但必须加入控件类型. 许多书籍都在类向导中建立.我 ...

  2. android listview中item通过viewpager实现《IT蓝豹》

    android listview中item通过viewpager实现 android listview中item通过viewpager实现,每一个item都支持viewpager实现图片切换功能.本项 ...

  3. NTKO OFFICE文档控件

    目录 前言 什么是ntko 准备工作 实战演练 总结 一.前言 Web开发中经常需要用到在线处理office文档的功能,现在市面上有一些常用的Web页面调用显示Office的控件技术,用起来很方便. ...

  4. 寒假生活第一天——Github初体验

    快开学了,今天体验了一下github这个对我来说很是神秘的东西 它的定义来源于百度百科,如有异议,那就有吧.//gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格 ...

  5. Fixation index

    :或者1.简单介绍 固定指数(FST)是一种由遗传结构决定的种群分化指标.它通常是由遗传多态性数据,如单核苷酸多态性(SNP)或微卫星估计.作为莱特f统计的一个特例,它是种群遗传学中最常用的统计方法之 ...

  6. VSC KeyNote

    [VSC KeyNote] 1.前后跳转. Alt + LeftArrow, Alt + RightArrow 2.缩进问题. vsc默认缩进为4,但js代码里缩进依旧是2. 因为vscode默认启用 ...

  7. 生产环境nginx上传文件报错413 Request Entity Too Large

    修改nginx配置文件/etc/nginx/nginx.conf 在http{}中添加 client_max_body_size 100m; 意思是设置上传文件大小

  8. jenkins动态参数插件Dynamic Parameter安装及简单使用

    插件安装: 1.先下载插件hpi文件到本地   jenkins插件下载地址 http://mirror.xmission.com/jenkins/plugins/ http://updates.jen ...

  9. linux 查看端口占用

    参考 https://www.cnblogs.com/wangtao1993/p/6144183.html lsof -i:8000

  10. phpstorm添加站点

    1.在界面上快捷键 ctrl+alt+s 或打开File->settings 2.找到Deployment 设置完后确定即可使用.