摘要:本文将带你了解Android应用开发之Android源码分析之QMUIGroupListSectionHeaderFooterView的属性样式讲解,希望本文对大家学Android有所帮助。
本文将带你了解Android应用开发之Android源码分析之QMUIGroupListSectionHeaderFooterView的属性样式讲解,希望本文对大家学Android有所帮助。
上篇文章分析了QMUIGroupListSectionHeaderFooterView的类结构,那么这个自定义的控件,用到了哪些样式属性呢?如果了解清楚了,那么在我们自己就可以配相应的样式了。
通过构造函数进入到R.attr.QMUIGroupListSectionViewStyle里面去看看。只是一个引用,如下图,看来在其他地方定义了。
搜索一下QMUIGroupListSectionViewStyle。在qmui_themes.xml和qmui_themes_compat.xml文件中都有定义。随便选择一个进去看看,原来是样式QMUI.GroupListSectionView。
点击QMUI.GroupListSectionView进去看看。看到这里定义了具体样式,设置上下左右各个内边距。
<style name="QMUI.GroupListSectionView" type="text/css"><item name="android:paddingLeft">attr/qmui_content_padding_horizontal</item> <item name="android:paddingRight">attr/qmui_content_padding_horizontal</item> <item name="android:paddingTop">@dimen/qmui_group_list_section_header_footer_padding_vertical </item> <item name="android:paddingBottom">@dimen/qmui_group_list_section_header_footer_padding_vertical </item></style>
那么这些内边距的值又是多少呢?我们点击第一个attr/qmui_content_padding_horizontal进去看看(用attr表示启用的是主题样式属性,可以随着主题变化而变化)。来到了qmui_attrs_base.xml文件,在第一行就看到了。这个格式定义成了dimesion。
<resources> <!-- 已废弃 --> <!-- margin 和 padding 等使用的内容通用水平间距 --></attr></attr></resources>
那我们到dimesion的定义去看看,搜索qmui_content_padding_horizontal找到了qmui_dimens.xml文件,里面有qmui_content_padding_horizontal的定义。又指向了qmui_content_spacing_horizontal,而qmui_content_spacing_horizontal被定义为16dp。
<!-- 全局统一的界面左右间距,例如列表分隔线inset --><dimen name="qmui_content_padding_horizontal">@dimen/qmui_content_spacing_horizontal</dimen> <!-- 已废弃 --><dimen name="qmui_content_spacing_horizontal">16dp</dimen> <!-- margin 和 padding 等使用的内容通用水平间距 -->
看来这个值被定义为了16dp。不过我们在使用时,最好不要直接写死为16dp,因为不同的系统版本,不同的分辨率,不同的主题,可能这个值都要不一样,这也是为什么值的引用要绕来绕去了。比如qmui_themes.xml和qmui_themes_compat.xml就是两种主题。
同样的方式,我们可以找到其他边距的具体值。
最后,再看看qmui_group_list_section_layout.xml布局文件和group_list_section_header_textView控件,看他们自身用了哪些属性。通过代码可见,只是设置了字体颜色、字体大小和gravity。
<!--xml version="1.0" encoding="utf-8"--><merge android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="https://schemas.android.com/apk/res/android"> <textview android:gravity="left" android:id="@+id/group_list_section_header_textView" android:layout_height="wrap_content" android:layout_width="match_parent" android:textcolor="attr/qmui_config_color_gray_3" android:textsize="@dimen/qmui_group_list_section_header_footer_text_size"></textview></merge>
总结一下QMUIGroupListSectionHeaderFooterView的样式都用了哪些。
首先外层是一个LinearLayout,设置了4个padding值。在LinearLayout有一个TextView,设置了字体颜色、字体大小、gravity属性。
具体的值如下。如果我们要做出一样的效果,只需要设置同样的属性即可。
控件
属性
属性值
LinearLayout
paddingLeft
attr/qmui_content_padding_horizontal
说明:值是16dp
paddingRight
attr/qmui_content_padding_horizontal
说明:跟左边距相同。
paddingTop
@dimen/qmui_group_list_section_header_footer_padding_vertical
说明:值为8dp
paddingBottom
@dimen/qmui_group_list_section_header_footer_padding_vertical
说明:跟上边距相同。
TextView
textSize
@dimen/qmui_group_list_section_header_footer_text_size
说明:值是13sp
textColor
attr/qmui_config_color_gray_3
gravity
left
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注移动开发之Android频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号