我们的应用中,常常有一些统一的组件,这时候应该用style来修饰。这样的话,修改起来也方便,代码也更简洁

比如,下面的代码,没有用style修饰

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:orientation="vertical" >
  5.  
  6. <TextView
  7.  
  8. android:textColor="@color/white"
  9. android:layout_height="36dp"
  10. android:layout_width="match_parent"
  11. android:gravity="center_vertical" />
  12. <TextView
  13. android:id="@+id/tv_1"
  14. android:textColor="@color/white"
  15. android:layout_height="36dp"
  16. android:layout_width="match_parent"
  17. android:gravity="center_vertical"
  18. />
  19. <TextView
  20. android:id="@+id/tv_3"
  21. android:textColor="@color/white"
  22. android:layout_height="36dp"
  23. android:layout_width="match_parent"
  24. android:gravity="center_vertical" />
  25. <TextView
  26. android:id="@+id/tv_2"
  27. android:textColor="@color/white"
  28. android:layout_height="36dp"
  29. android:layout_width="match_parent"
  30. android:gravity="center_vertical" />
  31.  
  32. </LinearLayout>

下面的代码使用了style,更加简洁,也好维护

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:orientation="vertical" >
  5.  
  6. <TextView
  7. android:id="@+id/tv_0"
  8. style="@style/text_style" />
  9. <TextView
  10. android:id="@+id/tv_1"
  11. style="@style/text_style"
  12. />
  13. <TextView
  14. android:id="@+id/tv_2"
  15. style="@style/text_style"/>
  16. <TextView
  17. android:id="@+id/tv_3"
  18. style="@style/text_style" />
  19. </LinearLayout>
  20.  
  21. <!--styles.xml-->
  22. <style name="text_style">
  23. <item name="android:textColor">@color/white</item>
  24. <item name="android:layout_height">36dp</item>
  25. <item name="android:layout_width">match_parent</item>
  26. <item name="android:gravity">center_vertical</item>
  27. </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. VS2005 VS2008 Manifest 配置问题总结

    一.问题 编译某个遗留工程后,运行程序时报错,“由于应用程序的配置不正确,应用程序无法启动.重新安装应用程序可能会解决这个问题.” 查看生成的Manifest文件如下: <?xml versio ...

  2. yii执行原理

    应用执行流程: 浏览器向服务器发送 Http Request | 控制器(protected/controllers) | |---> Action | 创建模型 (Model) | 检查$_P ...

  3. 安装Hadoop系列 — 安装Eclipse

    1.下载 Eclipse从 http://www.eclipse.org/downloads/index-developer.php下载合适版本,如:Eclipse IDE for C/C++ Dev ...

  4. 主机头部分 www有和无是有区别的

    关于主机部分www的问题: case 1: frontend web_service bind *:80 bind *:443 ssl crt /etc/haproxy/cert.pem acl ww ...

  5. 关于Firefox浏览器如何支持ActiveX控件,一个小的Hellow World

    今天尝试开发一个Firefox的插件.虽然比较简单,网上也有很多教程,但是感觉一些教程写的比较麻烦,在初步的开发过程中并没有用到那些东西,于是自己把开发过程记录下来.我是根据Mozilla官方教程开发 ...

  6. python 控制vbox虚拟机

    (本机环境:win7:python 2.7.9: vbox 4.3.12) 目标: 完成官网(https://pypi.python.org/pypi/pyvbox)上的demo: > pyth ...

  7. Android 之 内存管理-查看内存泄露(三)

    概述 在android的开发中,要时刻主要内存的分配和垃圾回收,因为系统为每一个dalvik虚拟机分配的内存是有限的,在google的G1中,分配的最大堆大小只有16M,后来的机器一般都为24M,实在 ...

  8. 安装nging,php

    http://www.zihou.me/html/2010/11/14/2658.html http://www.linuxidc.com/Linux/2011-04/34964p4.htm http ...

  9. CSS sprites 技术

    Css Sprites 技术逐渐流行,各大网站上都可以看到它的身影. 但从本质上,Css Sprites 只是 Css 技术的一个使用小窍门,初学者也能快速上手. Css Sprites 简单解释: ...

  10. Java集群优化——dubbo+zookeeper构建高可用分布式集群

    不久前,我们讨论过Nginx+tomcat组成的集群,这已经是非常灵活的集群技术,但是当我们的系统遇到更大的瓶颈,全部应用的单点服务器已经不能满足我们的需求,这时,我们要考虑另外一种,我们熟悉的内容, ...