Android布局系统与动态布局优化实践

Android 的布局系统真的是个老生常谈但又绕不开的东西。各种布局你听过不少,但用顺手的不多。这篇文章把常用的布局方式梳理得挺清楚,从LinearLayoutRelativeLayoutConstraintLayout都有,而且讲得还蛮实用,不是那种只看理论的。

动态布局这块也有提,像用LayoutInflater在代码里加载布局、用ViewStub优化性能这些都挺常用的。如果你平时做界面调整多,或者经常需要动态加控件,文章里的示例代码可以直接上手跑,省你不少试错时间。

ConstraintLayout那段我觉得讲得还不错,是它怎么减少嵌套、怎么拖线设置约束,用图形编辑器配合起来还蛮高效。再加上文章还带了个可直接运行的示例包,动手练练也方便。

对了,文末列了一堆相关资源,像RelativeLayout 实例流式布局这些,平时查查对照看也挺有的。

,如果你想搞清楚 Android 布局的来龙去脉,尤其是怎么选、怎么用、怎么优化,这篇值得收藏一份。

rar
Layout.rar 预估大小:65个文件
folder
Layout 文件夹
file
.project 842B
file
project.properties 563B
folder
src 文件夹
folder
edu 文件夹
folder
cuit 文件夹
folder
layoutdemo 文件夹
file
Activity2.java 540B
file
LayoutDemoActivity.java 881B
file
AndroidManifest.xml 1KB
folder
res 文件夹
folder
drawable-ldpi 文件夹
file
ic_launcher.png 1KB
folder
drawable-hdpi 文件夹
file
ic_launcher.png 1KB
file
ic_action_search.png 3KB
folder
values-v11 文件夹
file
styles.xml 94B
folder
menu 文件夹
file
activity_layout_demo.xml 240B
file
activity2.xml 263B
folder
drawable-mdpi 文件夹
file
ic_launcher.png 1KB
file
ic_action_search.png 3KB
folder
layout 文件夹
file
relative_layout2.xml 2KB
file
table_layout.xml 2KB
file
relative_layout.xml 798B
file
activity_activity2.xml 659B
file
activity_scroll_layout.xml 2KB
file
activity_layout_demo.xml 514B
file
layout_test.xml 428B
file
activity_relative_layout.xml 953B
file
linear_layout.xml 2KB
folder
values-sw600dp 文件夹
file
dimens.xml 203B
folder
drawable-xxhdpi 文件夹
file
ic_launcher.png 24KB
folder
drawable-xhdpi 文件夹
file
ic_launcher.png 2KB
file
ic_action_search.png 3KB
folder
values 文件夹
file
strings.xml 686B
file
styles.xml 697B
file
dimens.xml 220B
folder
values-sw720dp-land 文件夹
file
dimens.xml 277B
folder
layout-land 文件夹
file
activity_layout_demo.xml 387B
folder
values-v14 文件夹
file
styles.xml 108B
folder
.settings 文件夹
file
org.eclipse.jdt.core.prefs 177B
folder
assets 文件夹
folder
gen 文件夹
folder
edu 文件夹
folder
cuit 文件夹
folder
layoutdemo 文件夹
file
BuildConfig.java 161B
file
R.java 4KB
folder
libs 文件夹
file
android-support-v4.jar 543KB
file
.classpath 475B
file
proguard-project.txt 781B
file
ic_launcher-web.png 50KB
folder
bin 文件夹
file
resources.ap_ 37KB
folder
classes 文件夹
folder
edu 文件夹
folder
cuit 文件夹
folder
layoutdemo 文件夹
file
R$layout.class 736B
file
R$style.class 434B
file
R$dimen.class 464B
file
BuildConfig.class 347B
file
R$drawable.class 450B
file
Activity2.class 810B
file
R$attr.class 343B
file
LayoutDemoActivity.class 1KB
file
R$id.class 786B
file
R.class 683B
file
R$string.class 761B
file
R$menu.class 440B
file
AndroidManifest.xml 1KB
folder
dexedLibs 文件夹
file
android-support-v4-f00ff85e85e698e64c363d7dc9877d02.jar 206KB
file
jarlist.cache 120B
folder
res 文件夹
folder
drawable-ldpi 文件夹
file
ic_launcher.png 1KB
folder
drawable-hdpi 文件夹
file
ic_launcher.png 1KB
file
ic_action_search.png 409B
folder
drawable-mdpi 文件夹
file
ic_launcher.png 1KB
file
ic_action_search.png 311B
folder
drawable-xxhdpi 文件夹
file
ic_launcher.png 17KB
folder
drawable-xhdpi 文件夹
file
ic_launcher.png 2KB
file
ic_action_search.png 491B
file
Layout.apk 248KB
file
classes.dex 609KB
...
rar 文件大小:1.22MB