Android布局解析,图文(转)

简介: LinearLayout:相当于Java GUI中的FlowLayout(流式布局),就是说一个组件后边跟一个,挨着靠,一个组件把一行占满了,就靠到下一行。 linearlayoutdemo.xml ...

LinearLayout:相当于Java GUI中的FlowLayout(流式布局),就是说一个组件后边跟一个,挨着靠,一个组件把一行占满了,就靠到下一行。

linearlayoutdemo.xml

复制代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/L1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="3" android:background="#ffffb859" android:gravity="center" android:text="@string/ll" android:textSize="20sp" /> <LinearLayout android:id="@+id/L21" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="#ff3fb200" /> <TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="2" android:background="#ff3436b2" /> <TextView android:id="@+id/tv5" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3" android:background="#ff7a75b2" /> <LinearLayout android:id="@+id/L27" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="6" android:orientation="vertical"> <LinearLayout android:id="@+id/L37" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:background="#ff44ff16" android:orientation="horizontal"> </LinearLayout> <LinearLayout android:id="@+id/L32" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#ff382aff" android:gravity="center" android:orientation="horizontal"> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout>
复制代码

 

效果:

AbsolutelyLayout:绝对布局,相当于Java GUI中的空布局,就是啥也没有。组件的位置需要用坐标来显示。但是在android2.3之后已经弃用了,这种布局不能适应多种屏幕尺寸,局限性太大,但是对于独立开发者,单人单机来讲,用用也无妨。

absolutelayoutdemo.xml

复制代码
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00ffff"> <Button android:id="@+id/er" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="50dp" android:layout_y="50dp" android:background="#ff00ff" android:text="@string/al" /> </AbsoluteLayout>
复制代码

效果:

FrameLayout:这种布局是一层叠着一层,游戏类应用常会使用,涉及到NPC的构建视图等。

framelayoutdemo.xml

复制代码
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fl" android:textColor="#ffff2f25" android:textSize="40sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fl" android:textColor="#ff7e66ff" android:textSize="70sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fl" android:textColor="#ff5eff4f" android:textSize="50sp" /> </FrameLayout>
复制代码

效果:

RelativeLayout:关系布局,顾名思义,就是靠关系,谁在谁的左边谁在谁的上边,谁前边和谁对其等等。属性这里就不赘述了,需要时查API即可。

relativelayoutdemo.xml

复制代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/t1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#009922" android:text="@string/rl" android:textSize="40sp" /> <TextView android:id="@+id/t2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/t1" android:background="#ff8800" android:text="@string/rl" android:textSize="40sp" /> </RelativeLayout>
复制代码

效果:

GridLayout:网格布局,自定义N x N,可拓展到屏幕外围,猜想:当某些游戏应用的地图大于手机屏幕时,可以使用此种布局,一张图片太大,可以用多张图片进行拼接,内嵌FrameLayout实现NPC在地图上。

gridlayoutdemo.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:columnCount="6" android:orientation="horizontal" android:rowCount="10">    <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> <Button android:background="#ffff5651" /> <Button android:background="#ff45ff61" /> <Button android:background="#ff5d59ff" /> <Button android:background="#fff9ff52" /> <Button android:background="#ff31fff0" /> </GridLayout>
复制代码

效果:

 
 
http://www.cnblogs.com/somewhater/p/4625815.html
 
 
相关文章
|
4月前
|
数据采集 监控 API
告别手动埋点!Android 无侵入式数据采集方案深度解析
传统的Android应用监控方案需要开发者在代码中手动添加埋点,不仅侵入性强、工作量大,还难以维护。本文深入探讨了基于字节码插桩技术的无侵入式数据采集方案,通过Gradle插件 + AGP API + ASM的技术组合,实现对应用性能、用户行为、网络请求等全方位监控,真正做到零侵入、易集成、高稳定。
673 59
|
5月前
|
存储 消息中间件 人工智能
【05】AI辅助编程完整的安卓二次商业实战-消息页面媒体对象(Media Object)布局实战调整-按钮样式调整实践-优雅草伊凡
【05】AI辅助编程完整的安卓二次商业实战-消息页面媒体对象(Media Object)布局实战调整-按钮样式调整实践-优雅草伊凡
210 11
【05】AI辅助编程完整的安卓二次商业实战-消息页面媒体对象(Media Object)布局实战调整-按钮样式调整实践-优雅草伊凡
|
5月前
|
XML 存储 Java
【06】AI辅助编程完整的安卓二次商业实战-背景布局变更增加背景-二开发现页面跳转逻辑-替换剩余图标-优雅草卓伊凡
【06】AI辅助编程完整的安卓二次商业实战-背景布局变更增加背景-二开发现页面跳转逻辑-替换剩余图标-优雅草卓伊凡
162 3
【06】AI辅助编程完整的安卓二次商业实战-背景布局变更增加背景-二开发现页面跳转逻辑-替换剩余图标-优雅草卓伊凡
|
8月前
|
安全 Java Android开发
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
391 0
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
|
11月前
|
XML JavaScript Android开发
【Android】网络技术知识总结之WebView,HttpURLConnection,OKHttp,XML的pull解析方式
本文总结了Android中几种常用的网络技术,包括WebView、HttpURLConnection、OKHttp和XML的Pull解析方式。每种技术都有其独特的特点和适用场景。理解并熟练运用这些技术,可以帮助开发者构建高效、可靠的网络应用程序。通过示例代码和详细解释,本文为开发者提供了实用的参考和指导。
445 15
|
11月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
存储 Linux API
深入探索Android系统架构:从内核到应用层的全面解析
本文旨在为读者提供一份详尽的Android系统架构分析,从底层的Linux内核到顶层的应用程序框架。我们将探讨Android系统的模块化设计、各层之间的交互机制以及它们如何共同协作以支持丰富多样的应用生态。通过本篇文章,开发者和爱好者可以更深入理解Android平台的工作原理,从而优化开发流程和提升应用性能。
|
Java 调度 Android开发
安卓与iOS开发中的线程管理差异解析
在移动应用开发的广阔天地中,安卓和iOS两大平台各自拥有独特的魅力。如同东西方文化的差异,它们在处理多线程任务时也展现出不同的哲学。本文将带你穿梭于这两个平台之间,比较它们在线程管理上的核心理念、实现方式及性能考量,助你成为跨平台的编程高手。
|
XML 前端开发 Android开发
android 前端常用布局文件升级总结(二)
android 前端常用布局文件升级总结(二)
159 0
|
ARouter Android开发
Android不同module布局文件重名被覆盖
Android不同module布局文件重名被覆盖

推荐镜像

更多