android:hint=“密码” />
<Button
android:id=“@+id/button1”
android:layout_width=“100dp”
android:layout_height=“wrap_content”
android:layout_alignBaseline=“@+id/button2”
android:layout_alignBottom=“@+id/button2”
android:layout_marginRight=“14dp”
android:layout_toLeftOf=“@+id/button2”
android:text=“登录” />
<Button
android:id=“@+id/button2”
android:layout_width=“100dp”
android:layout_height=“wrap_content”
android:layout_alignRight=“@+id/et2”
android:layout_below=“@+id/et2”
android:layout_marginTop=“23dp”
android:text=“退出” />
(三)层布局FrameLayout
帧布局或叫层布局,从屏幕左上角按照层次堆叠方式布局,后面的控件覆盖前面的控件。
该布局在开发中设计地图经常用到,因为是按层次方式布局,我们需要实现层面显示的样式时就可以
采用这种布局方式,比如我们要实现一个类似百度地图的布局,我们移动的标志是在一个图层的上面。
在普通功能的软件设计中用得也不多。层布局主要应用就是地图方面。
上面有三层颜色,点击下面的案列上面会出现对应的样式
activity_main.xml中代码:
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:id=“@+id/LinearLayout1”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”
tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >
<FrameLayout
android:id=“@+id/frame”
android:layout_width=“match_parent”
android:layout_margin=“20dp”
android:layout_height=“wrap_content” >
<TextView
android:id=“@+id/text1”
android:layout_width=“match_parent”
android:layout_height=“300dp”
android:background=“#0000ff” />
<TextView
android:id=“@+id/text2”
android:layout_width=“match_parent”
android:layout_height=“300dp”
android:background=“#00ff00” />
<TextView
android:id=“@+id/text3”
android:layout_width=“match_parent”
android:layout_height=“300dp”
android:background=“#ff0000” />
<LinearLayout
android:id=“@+id/linear”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal” >
<Button
android:id=“@+id/button1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:layout_marginLeft=“20dp”
android:background=“#0000ff”
android:text=“颜色1”/>
<Button
android:id=“@+id/button2”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:layout_marginRight=“20dp”
android:layout_marginLeft=“20dp”
android:background=“#00ff00”
android:text=“颜色2”/>
<Button
android:id=“@+id/button3”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:background=“#ff0000”
android:layout_marginRight=“20dp”
android:text=“颜色3”/>
MainActivity.java中代码:
public class MainActivity extends Activity {
private FrameLayout frame;
private TextView text1;
private TextView text2;
private TextView text3;
private Button button1;
private Button button2;
private Button button3;
private OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
//删除
frame.removeView(text1);
//创建
frame.addView(text1);
break;
case R.id.button2:
frame.removeViewInLayout(text2);
frame.addView(text2);
break;
case R.id.button3:
frame.removeViewInLayout(text3);
frame.addView(text3);
break;
default:
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frame = (FrameLayout) findViewById(R.id.frame);
text1 = (TextView) findViewById(R.id.text1);
text2 = (TextView) findViewById(R.id.text2);
text3 = (TextView) findViewById(R.id.text3);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button1.setOnClickListener(listener);
button2.setOnClickListener(listener);
button3.setOnClickListener(listener);
}
}
(四)绝对布局AbsoluteLayout
绝对布局中将所有的子元素通过设置android:layout_x 和 android:layout_y属性,将子元素的坐标位置固定下来,即坐标(android:layout_x, android:layout_y) ,layout_x用来表示横坐标,layout_y用来表示纵坐标。屏幕左上角为坐标(0,0),横向往右为正方,纵向往下为正方。实际应用中,这种布局用的比较少,因为Android终端一般机型比较多,各自的屏幕大小。分辨率等可能都不一样,如果用绝对布局,可能导致在有的终端上显示不全等。所有基本不会使用,这里就不多介绍了。
(五)表格布局TableLayout
表格布局,适用于多行多列的布局格式,每个TableLayout是由多个TableRow组成,一个TableRow就表示TableLayout中的每一行,这一行可以由多个子元素组成。实际上TableLayout和TableRow都是LineLayout线性布局的子类。但是TableRow的参数android:orientation属性值固定为horizontal,且android:layout_width=MATCH_PARENT,android:layout_height=WRAP_CONTENT。所以TableRow实际是一个横向的线性布局,且所以子元素宽度和高度一致。
注意:在TableLayout中,单元格可以为空,但是不能跨列,意思是只能不能有相邻的单元格为空。
TableLayout常用属性:
android:shrinkColumns:设置可收缩的列,内容过多就收缩显示到第二行
android:stretchColumns:设置可伸展的列,将空白区域填充满整个列
android:collapseColumns:设置要隐藏的列
列的索引从0开始,shrinkColumns和stretchColumns可以同时设置。
子控件常用属性:
android:layout_column:第几列
android:layout_span:占据列数
效果图是一个计数器页面:
代码(这里这是页面,数据处理部分,完整功能计算器请访问:https://blog.csdn.net/qq_40205116/article/details/88550843):
<TableLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:id=“@+id/TableLayout1”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:stretchColumns=“*” >
<TextView
android:id=“@+id/text”
android:layout_width=“match_parent”
android:layout_height=“150dp”
android:background=“@android:color/holo_blue_bright”
android:textSize=“30dp”
android:gravity=“center|right”
android:text=“” />
<TableRow
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1” >
<Button
android:id=“@+id/btn01”
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“C” />
<Button
android:id=“@+id/btn02”
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“←” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“%” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“÷” />
<TableRow
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1” >
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“7” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“8” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“9” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“x” />
<TableRow
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1” >
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“4” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“5” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“6” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“-” />
<TableRow
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1” >
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“1” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“2” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“3” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“+” />
<TableRow
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_weight=“1” >
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“.” />
<Button
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:text=“0” />
<Button
android:id=“@+id/btn19”
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:layout_span=“2”
android:text=“=” />
(六)网格布局GridLayout
作为android 4.0 后新增的一个布局,与前面介绍过的TableLayout(表格布局)其实有点大同小异;
不过新增了一些东东
①跟LinearLayout(线性布局)一样,他可以设置容器中组件的对齐方式
②容器中的组件可以跨多行也可以跨多列(相比TableLayout直接放组件,占一行相比较)
因为是android 4.0新增的,API Level 14,在这个版本以前的sdk都需要导入项目。这里不解释。
常用属性:
排列对齐:
①设置组件的排列方式: android:orientation=“” vertical(竖直,默认)或者horizontal(水平)
②设置组件的对齐方式: android:layout_gravity=“” center,left,right,buttom
设置布局为几行几列:
①设置有多少行: android:rowCount=“4” //设置网格布局有4行
②设置有多少列: android:columnCount=“4” //设置网格布局有4列
设置某个组件位于几行几列
注:都是从0开始算的哦!
①组件在第几行: android:layout_row = “1” //设置组件位于第二行
②组件在第几列: android:layout_column = “2” //设置该组件位于第三列
设置某个组件横跨几行几列(合并):
横跨几行: android:layout_rowSpan = “2” //纵向横跨2行
横跨几列: android:layout_columnSpan = “3” //横向横跨2列
android:layout_gravity="fill"填充
效果图:
这里只简单的设置了一下按钮演示,大家也可以用gridLayout来做一个计数器页面(这里我就不写了,因为和上面那个表格布局差不多)。
<GridLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:id=“@+id/GridLayout1”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:columnCount=“4”
android:rowCount=“3”
android:orientation=“horizontal”
tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >
<Button
android:id=“@+id/button1”
android:layout_columnSpan=“2”
android:layout_gravity=“fill”
android:text=“bun11” />
<Button
android:id=“@+id/button2”
android:text=“bun12” />
<Button
android:id=“@+id/button3”
android:layout_rowSpan=“2”
android:layout_gravity=“fill”
android:text=“bun13” />
<Button
android:id=“@+id/button5”
android:text=“bun21” />
<Button
android:id=“@+id/button6”
android:text=“bun22” />
<Button
android:id=“@+id/button7”
android:text=“bun23” />
除上面讲过之外常用的几个布局的属性:
(1)layout_margin
用于设置控件边缘相对于父控件的边距
android:layout_marginLeft
android:layout_marginRight
android:layout_marginTop
android:layout_marginBottom
(2) layout_padding
用于设置控件内容相对于控件边缘的边距
android:layout_paddingLeft
android:layout_paddingRight
android:layout_paddingTop
android:layout_paddingBottom
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
最后
今天关于面试的分享就到这里,还是那句话,有些东西你不仅要懂,而且要能够很好地表达出来,能够让面试官认可你的理解,例如Handler机制,这个是面试必问之题。有些晦涩的点,或许它只活在面试当中,实际工作当中你压根不会用到它,但是你要知道它是什么东西。
最后在这里小编分享一份自己收录整理上述技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有 高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
【Android核心高级技术PDF文档,BAT大厂面试真题解析】
【算法合集】
【延伸Android必备知识点】
【Android部分高级架构视频学习资源】
Android精讲视频领取学习后更加是如虎添翼!进军BATJ大厂等(备战)!现在都说互联网寒冬,其实无非就是你上错了车,且穿的少(技能),要是你上对车,自身技术能力够强,公司换掉的代价大,怎么可能会被裁掉,都是淘汰末端的业务Curd而已!现如今市场上初级程序员泛滥,这套教程针对Android开发工程师1-6年的人员、正处于瓶颈期,想要年后突破自己涨薪的,进阶Android中高级、架构师对你更是如鱼得水,赶快领取吧!
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
可你的理解,例如Handler机制,这个是面试必问之题。有些晦涩的点,或许它只活在面试当中,实际工作当中你压根不会用到它,但是你要知道它是什么东西。
最后在这里小编分享一份自己收录整理上述技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有 高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
【Android核心高级技术PDF文档,BAT大厂面试真题解析】
[外链图片转存中…(img-60oldtuv-1713783290634)]
【算法合集】
[外链图片转存中…(img-EL9ZWqIy-1713783290635)]
【延伸Android必备知识点】
[外链图片转存中…(img-FgEKN6pl-1713783290636)]
【Android部分高级架构视频学习资源】
Android精讲视频领取学习后更加是如虎添翼!进军BATJ大厂等(备战)!现在都说互联网寒冬,其实无非就是你上错了车,且穿的少(技能),要是你上对车,自身技术能力够强,公司换掉的代价大,怎么可能会被裁掉,都是淘汰末端的业务Curd而已!现如今市场上初级程序员泛滥,这套教程针对Android开发工程师1-6年的人员、正处于瓶颈期,想要年后突破自己涨薪的,进阶Android中高级、架构师对你更是如鱼得水,赶快领取吧!
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!