认识头部和部件 status_bar.xml
2013-12-31 11:58
330 查看
我们来从第1行看起 <?xml version="1.0" encoding="utf-8"?> 复制代码 这行描述了xml的版本(xml version="1.0")以及xml文件编码格式(encoding="utf-8") 第二行是一行很长的代码: <com.android.systemui.statusbar.phone.PhoneStatusBarView android:id="@id/status_bar" android:background="@drawable/status_bar_background" android:focusable="true" android:fitsSystemWindows="true" android:descendantFocusability="afterDescendants" xmlns:android="http://schemas.android.com/apk/res/android"> 复制代码 这是一个部件。我们把诸如com.android.systemui.statusbar.phone.PhoneStatusBarView称作一个部件类名。它反映了这个控件的部件类是什么。 例如我们经常看到的按钮,其实它们都是一个基础按钮类再加上各种自定义选项形成的。 我们将这行代码格式化一下: <com.android.systemui.statusbar.phone.PhoneStatusBarView android:id="@id/status_bar" android:background="@drawable/status_bar_background" android:focusable="true" android:fitsSystemWindows="true" android:descendantFocusability="afterDescendants" xmlns:android="http://schemas.android.com/apk/res/android"> 复制代码 可读性好多了 :> 现在开始分析: <、> 控件信息的开始和结束符号,需要配对开始和结束(例如<a>需要配对</a>,中间存放着它的子控件),如果你看到的结束符号是/>不是>,那就不用配对结束了(例如<a/>就不用再写一个</a>了) com.android.systemui.statusbar.phone.PhoneStatusBarView 基础控件 android:id="@id/status_bar" 控件属性的自定义(以此类推,android:background="@drawable/status_bar_background"等也是) 我们和下列代码(第7行)对比下: <ImageView android:id="@id/notification_lights_out" android:paddingLeft="6.0dip" android:paddingBottom="2.0dip" android:visibility="gone" android:layout_width="@dimen/status_bar_icon_size" android:layout_height="fill_parent" android:src="@drawable/ic_sysbar_lights_out_dot_small" android:scaleType="center" /> 复制代码 有没有发现上面代码的部件类名好短?因为ImageView这个部件是Android提供的,只要是Android就都会有,这时候就可以直接提供类名。 如果你不是使用Android提供的控件,就像com.android.systemui.statusbar.phone.PhoneStatusBarView那样,就要填写完整的包名。 一般来说,常见的部件类有以下几种(均为Android提供): Button 按钮,不用多说了 ImageView 显示图片的部件 TextView 显示文字的部件 在这个xml里面,你会碰到以下部件: com.android.systemui.statusbar.phone.PhoneStatusBarView 状态栏 com.android.systemui.TorchServiceView 具体我也不是很清楚,似乎是手电筒服务 com.android.systemui.statusbar.phone.BatteryIndicator 顶部方式显示的电池指示器 com.android.systemui.statusbar.phone.BatteryIndicatorCharging 同上,不过这是充电时候的 com.android.systemui.statusbar.NetworkSpeedView 网速显示 com.android.systemui.statusbar.policy.Clock 时钟,我们以后会经常和他打交道 com.android.systemui.statusbar.StatusBarIconView 状态栏的省略号 com.android.systemui.statusbar.phone.IconMerger 不明,图标合并的? com.android.systemui.statusbar.phone.BatteryStatusIconView 数字和图标的电池状态指示器 ImageSwitcher 也是个可以显示图片的 com.android.systemui.statusbar.AnimatedImageView 动画图片 com.android.systemui.statusbar.phone.TickerView 弹出通知的显示就靠他了 Chronometer 秒表 嗯,大概就那么多!
看一个来自第24行的线性布局起始代码: <LinearLayout android:orientation="horizontal" android:id="@id/ticker" android:paddingLeft="6.0dip" android:animationCache="false" android:layout_width="fill_parent" android:layout_height="fill_parent"> 复制代码 从LinearLayout我们可以知道它是一个线性布局容器,下面的属性我们只挑选几个来说明,其它留待后面讲述。
无标题.png (9.41 KB, 下载次数: 0) 下载附件 保存到相册发送到手机
复制代码 无标题3.png (10.84 KB, 下载次数: 0) 下载附件 保存到相册发送到手机 这段代码是指定这个部件和父部件/容器的关系,取值“fill_parent”时,宽度=整个父部件/容器的宽度;取值“wrap_content”时,宽度=显示内容所需的宽度;取值“match_parent”时,和fill_parent一样;取值具体数值(例如200px)时,宽度=所给的具体数值。
复制代码 这个属性可以表示部件的权重,默认为0(显示多少东西就占用多少空间),数值越低(起作用的话最小为1)的话,在分配剩余空间的时候分得的空间越大。 无标题2.png (5.43 KB, 下载次数: 0) 下载附件 保存到相册发送到手机 再来看34行: <LinearLayout android:gravity="center" android:id="@id/returnToDriveModeScreen" android:background="@drawable/status_bar_orange_bar_bg" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent"> 复制代码
复制代码 很多时候我们要要求一个容器里面的部件按一定规律对齐,重力就是容器内部件对齐的一种手段,可以将全部部件居左、居中、居右。 无标题1.png (6.8 KB, 下载次数: 0) 下载附件 保存到相册发送到手机
<include android:id="@id/signal_cluster" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/signal_cluster_view" /> 复制代码 include严格来说是一种特殊部件,它是一种引用部件,你可以看成,这里有一个部件,里面还有别的布局文件控制。 例如上面的代码就引用了layout/signal_cluster_view.xml文件的内容了。 |
一个月米见,大家是不是有点想我呢?学生党就是坑,手机时常要受到成绩的影响,苦逼…… 上一节课,我们讲了MIUISystem.apk反编译后的结构,并且找到了掌管状态栏布局的status_bar.xml。这节课,我们来看看status_bar.xml这个文件怎样构成了看到的状态栏。
相关文章推荐
- 状态栏图标status_bar.xml
- XMLHTTPRequest状态status完整列表
- 《Android开发从零开始》——19.Status Bar Notifications学习
- View controller-based status bar appearance
- iOS-Hide Status bar
- AJAX问题之XMLHttpRequest status = 0
- 通知栏提示 Status Bar Notifications
- 菜鸟入坑》spring源码初步认识(对XML的解析)
- 不同版本(2.3-3.1)web.xml文件的schema头部声明
- XMLHttpRequest 的readyState 对象以及关于请求头status 的含义
- 第五周第2天XML初步认识(二)
- View controller-based status bar appearance
- Ajax 和 XML: 五个很酷的 Ajax 小部件
- IOS status bar
- Android Status bar添加耳机图标
- 认识axure部件库中各个部件的属性
- 【Android基础学习】Android使用fitsSystemWindows属性实现–状态栏【status_bar】各版本适配方案
- IOS7 The Status Bar
- LinqToXML中的XmlDocument去除头部声明写法
- Android使用fitsSystemWindows属性实现--状态栏【status_bar】各版本适配方案