我们的应用中,常常有一些统一的组件,这时候应该用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修饰的更多相关文章

  1. Android使用默认样式创建View的几个姿势

    以下内容是分析安卓源码所得: 1: 使用默认样式创建View的方式, 源码文件 Button.Java  注:此文参考http://www.linzenews.com/ 中的内容所写,如侵删! 2: ...

  2. [iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)

    A.导航栏两侧文字按钮 1.需求: 所有导航栏两侧的文字式按钮统一样式 普通样式:橙色 高亮样式:红色 不可用样式:亮灰 阴影:不使用 字体大小:15   github: https://github ...

  3. Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template

    在上一篇,介绍了Visual State Manager视觉状态管理器,其中涉及到控件的样式(Style)和模板(Template),本篇将详细介绍样式(Style)和模板(Template)在Sil ...

  4. Java接口统一样式返回模板

    Java接口统一样式返回模板 背景 在进行接口开发时,一般需要一个固定的返回样式,成功和失败的时候,都按照这种格式来进行统一的返回,这样,在与其他人进行接口之间的联调时不会显得很杂乱无章.而这种固定的 ...

  5. 样式和模板快速入门Style,Template

    http://www.cnblogs.com/jv9/archive/2010/04/14/1711520.html 样式(Style)和模板(Template)的定义 在Silverlight中,样 ...

  6. Android中自定义样式与View的构造函数中的第三个参数defStyle的意义

    零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...

  7. 样式表中的 element.style样式如何修改

    我们在写前面 web样式的时候,会发现有些时候,我们怎么修改 style里面的值,页面上的样式都不会修改,当你用工具查看时,会发现里面会有 element.style的值,这个值还找不到是在哪里出现的 ...

  8. js中获取样式的俩种方法 style.color和style['color'] 区别

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. VUE中的style 样式处理的Scope (<style scope>)

    在VUE组件中,为了让样式私有化,不对全局造成污染,可以在style标签上添加scoped属性以表示它的只属于当下的模块. 但是这样的话,就会导致无法修改其他第三方组件样式,或者是内嵌的样式,解决方案 ...

随机推荐

  1. jstack(查看线程)、jmap(查看内存)和jstat(性能分析)

    公司内部同事分享的一篇文章 周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令.供大家参考 1.Jstack 1.1 ...

  2. Servlet课程0425(七) 到数据库中去验证用户,同时防止SQL注入漏洞

    Login.java //登录界面 package com.tsinghua; import javax.servlet.http.*; import java.io.*; public class ...

  3. 《 UNIX网络编程》源码的使用

    学习编程这东西,看代码,改代码,运行代码这样才能学到实际东西!本书说在www.unpbook.com可以获取源码,不过打不开!所以google unpv13e.tar.gz 并在网络上找到了:源码:h ...

  4. windows编译 obs-studio

    github下载源码 https://github.com/jp9000/obs-studio 还需要一个开发包 http://code.fosshub.com/OBS/download/depend ...

  5. nginx+lua+redis实现logserver

    http://www.baidu.com/s?wd=nginx lua&pn=10&oq=nginx lua&tn=baiduhome_pg&ie=utf-8& ...

  6. J2EE中你必须了解的13种技术规范

    1)JDBC(Java Database Connectivity): JDBC API为访问不同的数据库提供了一种统一的途径,象ODBC一样,JDBC对开发者屏蔽了一些细节问题,另外,JDCB对数据 ...

  7. bzoj1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    筛法. 枚举每个数,它会对它的倍数的答案有贡献. 数大了以后,倍数相应少了很多.比枚举每个数的约数要好的多. 自己yy了一种分步做法.小于sqrt(m)被当作约数枚举,大于sqrt(m)的枚举倍数. ...

  8. 前端js框架收藏

    1. AngularJS :AngularJS是为克服HTML在构建应用上的不足而设计的. 2. knockout 3. avalon :MVVM是前端究极的解决方案,因此之后我大多数时间都在折腾av ...

  9. 【转】Java 截取字符串

    原文网址:http://blog.csdn.net/yelangjueqi/article/details/9149699 截取字符串常用方法: 1.length() 字符串的长度 例:char ch ...

  10. (十)学习CSS之padding属性

    浏览器支持 所有浏览器都支持 padding 属性. 注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit". 定义和用法 pa ...