Android成长之路-编码实现软件界面
实现一个登陆界面:
相对布局:
- package cn.csdn.codeui;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- public class LoginRelativeActivity extends Activity {
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initUI();
- }
- private void initUI() {
- RelativeLayout rlayout = new RelativeLayout(this);
- int id = 100;
- /**添加一个TextView*/
- TextView textView1 = new TextView(this);
- /**android:id=""*/
- textView1.setId(id);
- /**android:text="用户名:"*/
- textView1.setText("用户名:");
- /**android:layout_width="wrap_content"
- android:layout_height="wrap_content"*/
- RelativeLayout.LayoutParams textParams1 = new RelativeLayout.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- /**android:layout_alignParentLeft="true"*/
- textParams1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
- rlayout.addView(textView1, textParams1);
- //////////
- int id1 = 200;
- EditText userEdit = new EditText(this);
- userEdit.setId(id1);
- RelativeLayout.LayoutParams EditParams1 = new RelativeLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- /**android:layout_toRightOf="id的值"*/
- EditParams1.addRule(RelativeLayout.RIGHT_OF, id);
- rlayout.addView(userEdit, EditParams1);
- //////////
- int Id = 300;
- TextView textView2 = new TextView(this);
- textView2.setId(Id);
- textView2.setText("密码 :");
- RelativeLayout.LayoutParams TextParams2 = new RelativeLayout.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- TextParams2.addRule(RelativeLayout.BELOW, id1);
- rlayout.addView(textView2, TextParams2);
- //////////
- int Id1 = 400;
- EditText passEdit = new EditText(this);
- passEdit.setId(Id1);
- RelativeLayout.LayoutParams EditParams2 = new RelativeLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- EditParams2.addRule(RelativeLayout.BELOW, id1);
- EditParams2.addRule(RelativeLayout.RIGHT_OF, Id);
- rlayout.addView(passEdit, EditParams2);
- //////////
- int Id2 = 500;
- Button login = new Button(this);
- login.setId(Id2);
- login.setText("登陆");
- RelativeLayout.LayoutParams loginParams = new RelativeLayout.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- loginParams.addRule(RelativeLayout.BELOW, Id1);
- loginParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
- rlayout.addView(login, loginParams);
- //////////
- Button insert = new Button(this);
- insert.setText("注册");
- RelativeLayout.LayoutParams insertParams = new RelativeLayout.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- insertParams.addRule(RelativeLayout.BELOW, Id1);
- insertParams.addRule(RelativeLayout.LEFT_OF, Id2);
- rlayout.addView(insert, insertParams);
- setContentView(rlayout);
- }
- }
效果图:
表格布局:
- package cn.csdn.codeui;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TableLayout;
- import android.widget.TableRow;
- import android.widget.TextView;
- public class LoginTableActivity extends Activity {
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initUI();
- }
- private void initUI() {
- ///表格布局
- TableLayout tlayout = new TableLayout(this);
- tlayout.setColumnStretchable(1, true);
- ///行
- TableRow tableRow1 = new TableRow(this);
- TextView textView1 = new TextView(this);
- textView1.setText("用户名:");
- tableRow1.addView(textView1);
- EditText userEdit = new EditText(this);
- tableRow1.addView(userEdit);
- tlayout.addView(tableRow1);
- TableRow tableRow2 = new TableRow(this);
- TextView textView2 = new TextView(this);
- textView2.setText("密码:");
- tableRow2.addView(textView2);
- EditText passEdit = new EditText(this);
- tableRow2.addView(passEdit);
- tlayout.addView(tableRow2);
- TableRow tableRow3 = new TableRow(this);
- Button btn0 = new Button(this);
- btn0.setText("登录");
- tableRow3.addView(btn0);
- Button btn1 = new Button(this);
- btn1.setText("注册");
- tableRow3.addView(btn1);
- tlayout.addView(tableRow3);
- setContentView(tlayout);
- }
- }
效果图:
线性布局:
- package cn.csdn.codeui;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- public class LoginLinearActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- init();
- }
- private void init() {
- //线性布局
- LinearLayout linearLayout = new LinearLayout(this);
- /**android:orientation="vertical"*/
- linearLayout.setOrientation(LinearLayout.VERTICAL);
- LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
- LayoutParams.FILL_PARENT);
- //////////
- TextView userText = new TextView(this);
- userText.setText("用户名:");
- LayoutParams userTextParams = new LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- linearLayout.addView(userText, userTextParams);
- //////////
- EditText userEdit = new EditText(this);
- LayoutParams userEditParams = new LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- linearLayout.addView(userEdit, userEditParams);
- //////////
- TextView passText = new TextView(this);
- passText.setText("密码:");
- LayoutParams passTextParams = new LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- linearLayout.addView(passText, passTextParams);
- //////////
- EditText passEdit = new EditText(this);
- LayoutParams passEditParams = new LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- linearLayout.addView(passEdit, passEditParams);
- //////////
- Button login = new Button(this);
- login.setText("登陆");
- LayoutParams loginParams = new LayoutParams(LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT);
- linearLayout.addView(login, loginParams);
- //////////
- Button insert = new Button(this);
- insert.setText("注册");
- LayoutParams insertParams = new LayoutParams(LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT);
- linearLayout.addView(insert, insertParams);
- setContentView(linearLayout, layoutParams);
- }
- }
效果图:
Android成长之路-编码实现软件界面的更多相关文章
- Android成长之路-实现简单动画
实现简单动画: 在drawable目录中放入图片, 并且创建xml文件 frame.xml 存入图片,如下: <pre class="html" name="cod ...
- Android成长之路-手势库的创建
手势库的创建: 使用SDK自带的例子GestureBuilder建立手势库,这个文件夹存在于android\android-sdk-windows \samples\android-10\Gest ...
- Android成长之路-手势识别的实现
手势识别系统: 先把手势库放到项目中:(创建手势库见下一篇博客) 在res文件夹下新建一个名为raw的文件夹,然后把手势库放进去 然后开始项目的创建: strings.xml: <?xml ...
- Android成长之路-LayoutInflater和inflate的用法
在这里用Tabhost的例子来说明: package cn.csdn.activity; import android.app.TabActivity; import android.os.Bundl ...
- Android成长之路-实现监听器的三种方法
第一种: 在Test类中 定义一个类接口OnClickListener 第二种:直接在Test类上写一个接口 其中的this相当于new OnClickListener()对象, 即class ...
- 单片机成长之路(51基础篇) - 004 STC89C52MCU 软件实现系统复位
用户应用程序在运行过程中,有时会有特殊需求,需要实现单片机系统复位(热启动之一),传统的8051单片机由于硬件上未支持此功能,用户必须用软件模拟实现,实现起来较麻烦.STC单片机增加了相应的硬件功能, ...
- 【腾讯Bugly干货分享】JSPatch 成长之路
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/579efa7083355a9a57a1ac5b Dev Club 是一个交流移动 ...
- 介绍开发Android手持终端PDA盘点APP软件
介绍开发Android手持终端PDA盘点APP软件 软件需要自动识别我导入的TXT格式或者excl格式的盘点表,然后自动生成一个复盘数据,做AB比对,界面上需要显示的有总数量,单品数量,条码,编码,商 ...
- --专访雷果国: 从1.5K到18K 一个程序员的5年成长之路--
导语:今年三月份,在CSDN博客和新浪微博上有一篇<从1.5K到18K,一个程序员的5年成长之路>被众人分享和传阅,这篇博文首先介绍了作者自学之初薄弱的基础,然后通过流水账形式分享了那个从 ...
随机推荐
- HC-07 蓝牙串口模块
http://www.wavesen.com/probig.asp?id=17 本模块为新推出的产品,各项功能和性能.及引脚封装,均兼容于HC-06. 为低成本需求的的客户推荐本产品.相比HC-06来 ...
- cocos3.0使用cocostudio动画帧结合地图对象键值创建精灵动画
内容例如以下: #include "cocos2d.h" #include "cocostudio/CocoStudio.h" //精灵猫和其它精灵的tag t ...
- uva 784 Maze Exploration(简单dfs)
这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...
- EF6 MVC5译文
Contoso大学的Web应用程序 你在本教程中将建立一个简单的大学网站. 用户可以查看和更新学生信息,当然也包括教师的.下列图表是你将创建的应用程序截屏. 本网站的UI样式来源于内置的模板,所以教程 ...
- cocos2dx 3.0研究(1)-- hello world程序
1. 在mac上构建hello world很easy ./setup.py source /Users/jiangxf/.bash_profile cocos new AliGame -p com.m ...
- 使用openURL实现程序间带参数跳转详解
使用openURL实现程序间带参数跳转详解 实现的效果:有两款应用A与B,A打开B A --> B 1. 新建工程B,bundle ID为com.YouXianMing.B 建立一个URL 这么 ...
- HDU 3949 XOR 高斯消元
题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k依照二进制拆分就可以 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输 ...
- 自定义崩溃界面 CustomActivityOnCrash
项目地址:https://github.com/Ereza/CustomActivityOnCrash The inner workings are based on ACRA's dialog re ...
- [Grunt] Development Automation Tasks with Grunt
With Grunt you can automate core tasks for your AngularJS project. In this lesson we will take a loo ...
- SELECT语句逻辑运行顺序,你知道吗?
引言 这不是一个什么多深的技术问题.多么牛叉的编程能力.这跟一个人的开发能力也没有很必定的直接关系,可是知道这些会对你的SQL编写,排忧及优化上会有很大的帮助.它不是一个复杂的知识点.可是一个很基础的 ...