实现一个登陆界面:

相对布局:

  1. package cn.csdn.codeui;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.ViewGroup.LayoutParams;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.RelativeLayout;
  8. import android.widget.TextView;
  9. public class LoginRelativeActivity extends Activity {
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. initUI();
  13. }
  14. private void initUI() {
  15. RelativeLayout rlayout = new RelativeLayout(this);
  16. int id = 100;
  17. /**添加一个TextView*/
  18. TextView textView1 = new TextView(this);
  19. /**android:id=""*/
  20. textView1.setId(id);
  21. /**android:text="用户名:"*/
  22. textView1.setText("用户名:");
  23. /**android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"*/
  25. RelativeLayout.LayoutParams textParams1 = new RelativeLayout.LayoutParams(
  26. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  27. /**android:layout_alignParentLeft="true"*/
  28. textParams1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  29. rlayout.addView(textView1, textParams1);
  30. //////////
  31. int id1 = 200;
  32. EditText userEdit = new EditText(this);
  33. userEdit.setId(id1);
  34. RelativeLayout.LayoutParams EditParams1 = new RelativeLayout.LayoutParams(
  35. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  36. /**android:layout_toRightOf="id的值"*/
  37. EditParams1.addRule(RelativeLayout.RIGHT_OF, id);
  38. rlayout.addView(userEdit, EditParams1);
  39. //////////
  40. int Id = 300;
  41. TextView textView2 = new TextView(this);
  42. textView2.setId(Id);
  43. textView2.setText("密码 :");
  44. RelativeLayout.LayoutParams TextParams2 = new RelativeLayout.LayoutParams(
  45. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  46. TextParams2.addRule(RelativeLayout.BELOW, id1);
  47. rlayout.addView(textView2, TextParams2);
  48. //////////
  49. int Id1 = 400;
  50. EditText passEdit = new EditText(this);
  51. passEdit.setId(Id1);
  52. RelativeLayout.LayoutParams EditParams2 = new RelativeLayout.LayoutParams(
  53. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  54. EditParams2.addRule(RelativeLayout.BELOW, id1);
  55. EditParams2.addRule(RelativeLayout.RIGHT_OF, Id);
  56. rlayout.addView(passEdit, EditParams2);
  57. //////////
  58. int Id2 = 500;
  59. Button login = new Button(this);
  60. login.setId(Id2);
  61. login.setText("登陆");
  62. RelativeLayout.LayoutParams loginParams = new RelativeLayout.LayoutParams(
  63. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  64. loginParams.addRule(RelativeLayout.BELOW, Id1);
  65. loginParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  66. rlayout.addView(login, loginParams);
  67. //////////
  68. Button insert = new Button(this);
  69. insert.setText("注册");
  70. RelativeLayout.LayoutParams insertParams = new RelativeLayout.LayoutParams(
  71. LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  72. insertParams.addRule(RelativeLayout.BELOW, Id1);
  73. insertParams.addRule(RelativeLayout.LEFT_OF, Id2);
  74. rlayout.addView(insert, insertParams);
  75. setContentView(rlayout);
  76. }
  77. }

效果图:

表格布局:

  1. package cn.csdn.codeui;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.ViewGroup.LayoutParams;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.TableLayout;
  8. import android.widget.TableRow;
  9. import android.widget.TextView;
  10. public class LoginTableActivity extends Activity {
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. initUI();
  14. }
  15. private void initUI() {
  16. ///表格布局
  17. TableLayout tlayout = new TableLayout(this);
  18. tlayout.setColumnStretchable(1, true);
  19. ///行
  20. TableRow tableRow1 = new TableRow(this);
  21. TextView textView1 = new TextView(this);
  22. textView1.setText("用户名:");
  23. tableRow1.addView(textView1);
  24. EditText userEdit = new EditText(this);
  25. tableRow1.addView(userEdit);
  26. tlayout.addView(tableRow1);
  27. TableRow tableRow2 = new TableRow(this);
  28. TextView textView2 = new TextView(this);
  29. textView2.setText("密码:");
  30. tableRow2.addView(textView2);
  31. EditText passEdit = new EditText(this);
  32. tableRow2.addView(passEdit);
  33. tlayout.addView(tableRow2);
  34. TableRow tableRow3 = new TableRow(this);
  35. Button btn0 = new Button(this);
  36. btn0.setText("登录");
  37. tableRow3.addView(btn0);
  38. Button btn1 = new Button(this);
  39. btn1.setText("注册");
  40. tableRow3.addView(btn1);
  41. tlayout.addView(tableRow3);
  42. setContentView(tlayout);
  43. }
  44. }

效果图:

线性布局:

  1. package cn.csdn.codeui;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.ViewGroup.LayoutParams;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.LinearLayout;
  8. import android.widget.TextView;
  9. public class LoginLinearActivity extends Activity {
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. // TODO Auto-generated method stub
  13. super.onCreate(savedInstanceState);
  14. init();
  15. }
  16. private void init() {
  17. //线性布局
  18. LinearLayout linearLayout = new LinearLayout(this);
  19. /**android:orientation="vertical"*/
  20. linearLayout.setOrientation(LinearLayout.VERTICAL);
  21. LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
  22. LayoutParams.FILL_PARENT);
  23. //////////
  24. TextView userText = new TextView(this);
  25. userText.setText("用户名:");
  26. LayoutParams userTextParams = new LayoutParams(
  27. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  28. linearLayout.addView(userText, userTextParams);
  29. //////////
  30. EditText userEdit = new EditText(this);
  31. LayoutParams userEditParams = new LayoutParams(
  32. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  33. linearLayout.addView(userEdit, userEditParams);
  34. //////////
  35. TextView passText = new TextView(this);
  36. passText.setText("密码:");
  37. LayoutParams passTextParams = new LayoutParams(
  38. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  39. linearLayout.addView(passText, passTextParams);
  40. //////////
  41. EditText passEdit = new EditText(this);
  42. LayoutParams passEditParams = new LayoutParams(
  43. LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  44. linearLayout.addView(passEdit, passEditParams);
  45. //////////
  46. Button login = new Button(this);
  47. login.setText("登陆");
  48. LayoutParams loginParams = new LayoutParams(LayoutParams.FILL_PARENT,
  49. LayoutParams.WRAP_CONTENT);
  50. linearLayout.addView(login, loginParams);
  51. //////////
  52. Button insert = new Button(this);
  53. insert.setText("注册");
  54. LayoutParams insertParams = new LayoutParams(LayoutParams.FILL_PARENT,
  55. LayoutParams.WRAP_CONTENT);
  56. linearLayout.addView(insert, insertParams);
  57. setContentView(linearLayout, layoutParams);
  58. }
  59. }

效果图:

Android成长之路-编码实现软件界面的更多相关文章

  1. Android成长之路-实现简单动画

    实现简单动画: 在drawable目录中放入图片, 并且创建xml文件 frame.xml 存入图片,如下: <pre class="html" name="cod ...

  2. Android成长之路-手势库的创建

      手势库的创建: 使用SDK自带的例子GestureBuilder建立手势库,这个文件夹存在于android\android-sdk-windows \samples\android-10\Gest ...

  3. Android成长之路-手势识别的实现

      手势识别系统: 先把手势库放到项目中:(创建手势库见下一篇博客) 在res文件夹下新建一个名为raw的文件夹,然后把手势库放进去 然后开始项目的创建: strings.xml: <?xml  ...

  4. Android成长之路-LayoutInflater和inflate的用法

    在这里用Tabhost的例子来说明: package cn.csdn.activity; import android.app.TabActivity; import android.os.Bundl ...

  5. Android成长之路-实现监听器的三种方法

      第一种:  在Test类中  定义一个类接口OnClickListener 第二种:直接在Test类上写一个接口 其中的this相当于new OnClickListener()对象, 即class ...

  6. 单片机成长之路(51基础篇) - 004 STC89C52MCU 软件实现系统复位

    用户应用程序在运行过程中,有时会有特殊需求,需要实现单片机系统复位(热启动之一),传统的8051单片机由于硬件上未支持此功能,用户必须用软件模拟实现,实现起来较麻烦.STC单片机增加了相应的硬件功能, ...

  7. 【腾讯Bugly干货分享】JSPatch 成长之路

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/579efa7083355a9a57a1ac5b Dev Club 是一个交流移动 ...

  8. 介绍开发Android手持终端PDA盘点APP软件

    介绍开发Android手持终端PDA盘点APP软件 软件需要自动识别我导入的TXT格式或者excl格式的盘点表,然后自动生成一个复盘数据,做AB比对,界面上需要显示的有总数量,单品数量,条码,编码,商 ...

  9. --专访雷果国: 从1.5K到18K 一个程序员的5年成长之路--

    导语:今年三月份,在CSDN博客和新浪微博上有一篇<从1.5K到18K,一个程序员的5年成长之路>被众人分享和传阅,这篇博文首先介绍了作者自学之初薄弱的基础,然后通过流水账形式分享了那个从 ...

随机推荐

  1. 获取 ext grid 选中行 对象

    在ext grid 中如何确定选中行?如何获取选中行数据? 其实很简单,用到了Ext.getCmp('id'),他可以获取到指定id的对象. grid 获取行对象: var row = Ext.get ...

  2. .NET 4.6的RyuJIT尾递归优化的Bug

    今天看到园子里有一篇新闻稿.NET 4.6的RyuJIT编译器中发现严重的Bug提到,在.Net 4.6的x64程序中默认启用新的JIT程序RyuJIT在处理尾递归指令的时候有一个Bug,导致无法得到 ...

  3. POJ 1286 Necklace of Beads(Polya简单应用)

    Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...

  4. Linux下OOM Killer机制详解

    http://www.cnblogs.com/ylqmf/archive/2012/11/05/2754795.html http://wuquan-1230.blog.163.com/blog/st ...

  5. java自动识别上传的apk版本号

    import java.util.List; public class ApkInfo { private String versionCode; private String versionName ...

  6. Unity3D面试题总结

    一.什么是渲染管道? 是指在显示器上为了显示出图像而经过的一系列必要操作. 渲染管道中的很多步骤,都要将几何物体从一个坐标系中变换到另一个坐标系中去. 主要步骤有: 本地坐标->视图坐标-> ...

  7. 【mybatis】mysql级联更新两个表或多张表的数据

    例如 info表和relation表有关联,现在要在一个sql语句中同时级联更新两张表的数据 update security_code_info info LEFT JOIN security_cod ...

  8. List of Chromium Command Line Switches(命令行开关集)——官方指定命令行更新网址

    转自:http://peter.sh/experiments/chromium-command-line-switches/ There are lots of command lines which ...

  9. 对java3d的位置理解

    以一个圆柱体为例: 圆柱体的一个特征点假设为(0,0,0),如下图示: 当特征点变为(0,0.4f,0)时,我们看到的圆柱体就如下所示: 当特征点变为(0,0.8f,0)时,我们看到的圆柱体就如下所示 ...

  10. iOS:切换视图时,反向传递数据方法一:通知

    通知方式: 1.有一个(单例)通知中心,负责管理iOS中的所有通知 2.需要获取某种通知,必须注册成为观察者(订阅) 3.不再需要取某种通知时,要取消注册. 4.你可以向通知中心发送某种通知,通知中心 ...