Android界面布局练习

一、实验目的

  1. 掌握常用的几种界面布局方法。
  2. 能够熟练综合应用各种布局方法进行界面设计。

二、实验内容

  1. 制作如下图所示的手机QQ登陆界面。

给控件绑定监听器,当用户点击登陆按钮时,把用户所填写的注册内容显示在“注册”按钮下面的文本框内。

2、课本上其它示例程序。
三、预备知识

四、实验步骤
1、新建一个Android项目,项目名称中须包含学号后三位,如“Project101”,否则作业无效。
2、综合利用所掌握的布局方法,实现如图1所示的手机QQ登陆界面。
3、 可以使用的资源图片:

4、不固定布局方法。

展示

代码

布局文件

<?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"android:orientation="horizontal"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/qq" /></LinearLayout><TableLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:stretchColumns="0,1"><TableRow><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/name" /><EditTextandroid:id="@+id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content" /></TableRow><TableRow><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/pwd" /><EditTextandroid:id="@+id/text2"android:inputType="textPassword"android:layout_width="wrap_content"android:layout_height="wrap_content" /></TableRow><TableRow><RadioGroupandroid:id="@+id/sex"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:orientation="horizontal"><RadioButtonandroid:id="@+id/sex1"android:checked="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/sex1" /><RadioButtonandroid:id="@+id/sex2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/sex2" /></RadioGroup><TextView /></TableRow><TableRow><CheckBoxandroid:id="@+id/check1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/ji" /><CheckBoxandroid:id="@+id/check2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/zi" /></TableRow><TableRow><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/zhu" /><Buttonandroid:id="@+id/deng"android:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="submit"android:text="@string/deng" /></TableRow><TableRow><TextViewandroid:id="@+id/text3"android:layout_width="wrap_content"android:layout_height="wrap_content" /></TableRow></TableLayout></LinearLayout>

strings.xml

<resources><string name="app_name">project047</string><string name="name">用户名</string><string name="pwd">密码</string><string name="sex1">男</string><string name="size">20dp</string><string name="sex2">女</string><string name="ji">记住密码</string><string name="zi">自动登陆</string><string name="deng">登陆</string><string name="zhu">注册</string>
</resources>

Main_Activity.java

package com.example.project047;import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;public class MainActivity extends AppCompatActivity {private String text1;private String text2;private String text3;private String sex;private String check1;private String check2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void submit(View view) {EditText editText1 = findViewById(R.id.text1);EditText editText2 = findViewById(R.id.text2);RadioGroup radioGroup = findViewById(R.id.sex);//        radioGroup.getCheckedRadioButtonId();
//        radioGroup.setOnCheckedChangeListener((group, checkId) -> {//            sex = checkId == R.id.sex1 ? "男" : "女";
//        });int a = radioGroup.getCheckedRadioButtonId();if (a == R.id.sex1) {sex = "男";} else {sex = "女";}/** System.out.println("a"+a);*  System.out.println("r"+R.id.sex1);* I/System.out: a2131165300*     r2131165300*/CheckBox checkBox1 = findViewById(R.id.check1);CheckBox checkBox2 = findViewById(R.id.check2);check1 = checkBox1.isChecked() ? "是" : "否";check2 = checkBox2.isChecked() ? "是" : "否";TextView textView = findViewById(R.id.text3);text1 = String.valueOf(editText1.getText());text2 = String.valueOf(editText2.getText());text3 = "用户名:" + text1 + "\n" + "密码:" + text2 + "\n" + "性别:" + sex + "\n"+ "记住密码:" + check1 + "\n自动登陆:" + check2;textView.setText(text3);}
}

Android界面布局练习相关推荐

  1. android界面布局

    [url=http://www.cnblogs.com/skynet/archive/2010/06/06/1752616.html]Android 开发之旅:view的几种布局方式及实践[/url] ...

  2. android storyboard,iOS中xib与storyboard原理,与Android界面布局的异同

    用文本标记语言来进行布局,用的最多的应该是HTML语言.HTML能够理解为有一组特殊标记的XML语言. 一.iOS中xib与storyboard显示原理 在iOS中基本的布置界面的方式有3种:代码.x ...

  3. android界面布局题,【填空题】Android 系统中, 用于定义布局显示在界面上的风格。...

    [填空题]Android 系统中, 用于定义布局显示在界面上的风格. 更多相关问题 [37]A.anotherB.each otherC.the otherD.one another Tabor ma ...

  4. android 网格界面,Android界面布局(4)—网格布局

    网格布局 网格布局(GridLayout)将用户界面划分为网格,界面元素可以随意摆放在这些网格中.网格布局比表格布局在界面设计上更加灵活,在网格布局中界面元素可以占用多个网格的,而在表格中只能将界面元 ...

  5. Android 界面布局之RelativeLayout

    Android 的 RelaliveLayout 布局的参数定义: android:layout_above="@id/xxx"  --将控件置于给定ID控件之上 android: ...

  6. android界面布局错位,IOS 浏览器页面布局错位(如:点不到)的分析与解决

    IOS 浏览器页面布局错位(如:点不到)的分析与解决 IOS 浏览器软键盘的拉起与收缩.微信 IOS 浏览器底部导航条的显示与隐藏,很容易导致页面布局错位(相对窗体的绝对定位元素): 明明按钮在这里, ...

  7. android 界面布局 很好的一篇总结 【转】

    布局:   在 android 中我们常用的布局方式有这么几种: 1.LinearLayout ( 线性布局 ) :(里面只可以有一个控件,并且不能设计这个控件的位置,控件会放到左上角) 线性布局分为 ...

  8. android 界面布局-各个布局的属性介绍,sharedpreferences原理

    TableLayout tableLayout = (TableLayout) findViewById(R.id.table01); /*创建列对象*/ TableRow tableRow = ne ...

  9. android 界面布局-各个布局的属性介绍,你值得拥有

    第三类:属性值为具体的像素值,如 30dip , 40px android:layout_marginBottom              离某元素底边缘的距离 android:layout_mar ...

最新文章

  1. Spring+Hibernate项目在weblogic中部署的一些问题
  2. webpack学习资料
  3. 磁盘操作系统是计算机语言吗,实时磁盘操作系统
  4. 自动登录ssh不需要输入密码
  5. 推荐 | 方便好用的浏览器插件
  6. python关键词大全_Python 批量获取Baidu关键词的排名并入库
  7. request.params 用法
  8. MySQL高级知识(三)——索引
  9. Flash研究(一)——本地通讯
  10. 「PKUSC2018」最大前缀和 LOJ#6433BZOJ5369
  11. 实验吧 天网管理系统writeup
  12. 真正的小说 真正的生活 真正的蜕变 真正的品味
  13. [JZOJ4378] 八卦天盘
  14. [Reproduced]Jerry Stackhouse Calls LeBron James
  15. dg怎么了(最近dg怎么了)
  16. IKAnalyzer中文分词分析内容目录
  17. 有个名叫史太滩的珠宝商带着块鸡蛋大的宝石乘船过江
  18. QT实现简单的塔防游戏
  19. 因缺失增量信息而导致recoverseg恢复失败的情况
  20. 房产管理系统架构分析

热门文章

  1. 独立成分分析 与 功能连接之间的关联尝试 by 张高燕
  2. Docker和k8s的区别与介绍
  3. ACP敏捷9.敏捷应用场景
  4. ffmpeg h265
  5. RocketMQ单机环境搭建
  6. 转载分享一批老外的超牛25行代码参赛作品的Flash源文件
  7. 医疗卫生信息化数据防泄漏保护系统解决方案
  8. VSCODE安装ChatGPT插件
  9. Elo第四代触摸一体机发布,助力全场景数字化转型
  10. request+python : shuold be true判等的问题