统一样式的View应该用style修饰
我们的应用中,常常有一些统一的组件,这时候应该用style来修饰。这样的话,修改起来也方便,代码也更简洁
比如,下面的代码,没有用style修饰
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <TextView android:textColor="@color/white"
android:layout_height="36dp"
android:layout_width="match_parent"
android:gravity="center_vertical" />
<TextView
android:id="@+id/tv_1"
android:textColor="@color/white"
android:layout_height="36dp"
android:layout_width="match_parent"
android:gravity="center_vertical"
/>
<TextView
android:id="@+id/tv_3"
android:textColor="@color/white"
android:layout_height="36dp"
android:layout_width="match_parent"
android:gravity="center_vertical" />
<TextView
android:id="@+id/tv_2"
android:textColor="@color/white"
android:layout_height="36dp"
android:layout_width="match_parent"
android:gravity="center_vertical" /> </LinearLayout>
下面的代码使用了style,更加简洁,也好维护
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <TextView
android:id="@+id/tv_0"
style="@style/text_style" />
<TextView
android:id="@+id/tv_1"
style="@style/text_style"
/>
<TextView
android:id="@+id/tv_2"
style="@style/text_style"/>
<TextView
android:id="@+id/tv_3"
style="@style/text_style" />
</LinearLayout> <!--styles.xml-->
<style name="text_style">
<item name="android:textColor">@color/white</item>
<item name="android:layout_height">36dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:gravity">center_vertical</item>
</style>
统一样式的View应该用style修饰的更多相关文章
- Android使用默认样式创建View的几个姿势
以下内容是分析安卓源码所得: 1: 使用默认样式创建View的方式, 源码文件 Button.Java 注:此文参考http://www.linzenews.com/ 中的内容所写,如侵删! 2: ...
- [iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)
A.导航栏两侧文字按钮 1.需求: 所有导航栏两侧的文字式按钮统一样式 普通样式:橙色 高亮样式:红色 不可用样式:亮灰 阴影:不使用 字体大小:15 github: https://github ...
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
在上一篇,介绍了Visual State Manager视觉状态管理器,其中涉及到控件的样式(Style)和模板(Template),本篇将详细介绍样式(Style)和模板(Template)在Sil ...
- Java接口统一样式返回模板
Java接口统一样式返回模板 背景 在进行接口开发时,一般需要一个固定的返回样式,成功和失败的时候,都按照这种格式来进行统一的返回,这样,在与其他人进行接口之间的联调时不会显得很杂乱无章.而这种固定的 ...
- 样式和模板快速入门Style,Template
http://www.cnblogs.com/jv9/archive/2010/04/14/1711520.html 样式(Style)和模板(Template)的定义 在Silverlight中,样 ...
- Android中自定义样式与View的构造函数中的第三个参数defStyle的意义
零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...
- 样式表中的 element.style样式如何修改
我们在写前面 web样式的时候,会发现有些时候,我们怎么修改 style里面的值,页面上的样式都不会修改,当你用工具查看时,会发现里面会有 element.style的值,这个值还找不到是在哪里出现的 ...
- js中获取样式的俩种方法 style.color和style['color'] 区别
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- VUE中的style 样式处理的Scope (<style scope>)
在VUE组件中,为了让样式私有化,不对全局造成污染,可以在style标签上添加scoped属性以表示它的只属于当下的模块. 但是这样的话,就会导致无法修改其他第三方组件样式,或者是内嵌的样式,解决方案 ...
随机推荐
- Fibonacci sequence 求余数
#include <iostream> using namespace std; int f(int n); int main() { int n; cin>>n; doubl ...
- SSL构建单双向https认证
1. SSL基本介绍 我们常常在使用网上银行时看到的连接都是以“https”开始的,那么这个https是什么呢?这其实是表示目前连接使用了SSL进加密,能保证客户端到服务器端的通信都在被保护起来,那 ...
- HeadFirst设计模式之RMI介绍
一.使用步骤 1.generate stubs and skeletons:Run rmic on the remote implementation class 如:D:\Workspaces\My ...
- 镜面电火花EDM加工技术资料,模具行业的人应该好好看看!
目前镜面电火花加工技术在精密型腔模具制造中逐步得以推广.本文就企业中镜面电火花加工应用的关键环节,结合实践分析了影响镜面加工性能的因素.通过控制各个工艺环节,可有效实现高质量.高效率的镜面电火花加工. ...
- node.js 模块和包
Node.js 的模块和包机制的实现参照了 CommonJS 的标准,但并未完全遵循.不过两者的区别并不大,一般来说你大可不必担心,只有当你试图制作一个除了支持 Node.js之外还要支持其他平台的模 ...
- 深入研究Java类加载机制
类加载是Java程序运行的第一步,研究类的加载有助于了解JVM执行过程,并指导开发者采取更有效的措施配合程序执行. 研究类加载机制的第二个目的是让程序能动态的控制类加载,比如热部署等,提高程序的灵活性 ...
- 抱怨IT公司人才缺乏?留住现有人才方是正途
摘要:员工的好坏决定着IT公司的未来,可很多IT公司在抱怨之时自己的人才却正在流失,如何留住现有的优秀员工?国外知名经理人Sharon Florentine建议:改善自己的管理.让员工不断地学习.创建 ...
- git整理纷乱的历史合并记录
https://github.com/Epix37/Hearthstone-Deck-Tracker 以上面版本库的master分支为例 父节点1 SHA-1: a21142968282ae49720 ...
- HTML5学习(十)---Web Workers
参考教程:http://www.w3school.com.cn/html5/html_5_webworkers.asp web worker 是运行在后台的 JavaScript,不会影响页面的性能. ...
- UVa 10900 (连续概率、递推) So you want to be a 2n-aire?
题意: 初始奖金为1块钱,有n个问题,连续回答对i个问题后,奖金变为2i元. 回答对每道题的概率在t~1之间均匀分布. 听到问题后有两个选择: 放弃回答,拿走已得到的奖金 回答问题: 如果回答正确,奖 ...