摘要:本文将带你了解Android应用开发之Android应用开发之布局管理详细教程,希望本文对大家学Android有所帮助。
本文将带你了解Android应用开发之Android应用开发之布局管理详细教程,希望本文对大家学Android有所帮助。
一、设计目的
了解四种布局管理器的区别和各自特别的属性 掌握四种布局管理器的应用场合和用法 灵活使用四种布局文件管理器和嵌套实现各种复杂布局 掌握复用XML布局文件的方法 掌握代码控制UI界面的方法
二、软硬件环境
开发环境:Android Studio
模拟运行:Android Emulator – Nexus_5X_API_24
三、实现过程及结果
3.1 用Java代码设置全屏:打开工程的主Activity文件,在onCreate方法中执行语句super.onCreate(saveInstanceState)之前,添加语句:
requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题栏this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏运营图标、点量等super.onCreate(savedInstanceState);
3.2 完成Android应用UI的开发
3.2.1 将主布局修改为线性布局
?12<linearlayout android:background="#FFFAE4" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="//schemas.android.com/apk/res/android"></linearlayout>
3.2.2 在主布局中添加一个现实logo的ImageView组件
?12<imageview android:layout_height="81dp" android:layout_width="match_parent" android:src="@mipmap/test3"></imageview>
3.2.3 主布局中继续添加一个线性布局,该布局分为两列,分别放置头像和表格布局,表格布局也分为两行,放置用户名和密码
<linearlayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal"> <imageview android:layout_height="90dp" android:layout_width="wrap_content" android:src="@mipmap/ic_launcher"> <tablelayout android:layout_height="wrap_content" android:layout_width="match_parent"><tablerow> <textview android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="账号:"> <edittext android:id="@+id/user" android:layout_height="wrap_content" android:layout_width="wrap_content"></edittext></textview></tablerow><tablerow> <textview android:layout_height="wrap_content" android:layout_width="wrap_content" android:minwidth="300px" android:text="密码:"> <edittext android:id="@+id/password" android:inputtype="textPassword" android:layout_height="wrap_content" android:layout_width="wrap_content"></edittext></textview></tablerow> </tablelayout> </imageview></linearlayout>
3.2.4 在主布局中继续添加一个登陆按钮
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:onClick="login"/>
3.2.5 在主布局中继续添加三个已选中的复选框,分别为记住密码,自动登陆和接收产品推广
<checkbox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="记住密码"><checkbox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="自动登录"><checkbox android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="接收推广"></checkbox></checkbox></checkbox>
3.2.6 在主布局中继续添加一个布局管理器,该布局管理中防止忘记密码和注册账号两个按钮
<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="忘记密码" android:onClick="forgetpassword"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="注册账号" android:onClick="register"/></FrameLayout>
3.2.7 在主布局中继续添加一个布局管理器,该布局管理器放置进度条和表示加载中的文本框
<linearlayout android:layout_height="63dp" android:layout_width="match_parent" android:orientation="vertical"> <textview android:id="@+id/loading" android:layout_height="wrap_content" android:layout_width="match_parent"> <progressbar android:layout_height="30dp" android:layout_marginbottom="10dp" android:layout_width="match_parent"> </progressbar></textview></linearlayout>
3.3 在主Activity文件中添加用于登陆的login方法,用于处理忘记密码的forgetPassword方法,用于打开注册界面的register方法
public void login(View view){ if( true ){StringBuilder sb = new StringBuilder(); sb.append("登录成功!"+"\n");sb.append("用户名:" + userName.getText().toString()+"\n");sb.append("密码:" + password.getText().toString()+"\n"); Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show(); Intent intent = new Intent();//登录到ResultActivity页面intent.setClass(this, ResultActivity.class);intent.putExtra("info", sb.toString());this.startActivity(intent); } } //打开忘记密码界面 public void forgetpassword(View view){ StringBuilder sb = new StringBuilder(); Intent intent = new Intent(); intent.setClass(this, ForgetPassActivity.class); intent.putExtra("info", sb.toString()); this.startActivity(intent); } //打开注册界面 public void register(View view){ StringBuilder sb = new StringBuilder(); Intent intent = new Intent(); intent.setClass(this, RegisterActivity.class); intent.putExtra("info", sb.toString()); this.startActivity(intent); }
3.4 界面布局后界面如图:
3.5 输入内容以及点击登陆后界面如图:
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注移动开发之Android频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号