我们的应用中,常常有一些统一的组件,这时候应该用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. UIActinSheet和UIActionSheetDelegate

    UIActinSheet和UIActionSheetDelegate 这个是就那个UIActionSheet对象  一般用来选择类型或者改变界面...还有更多应用 定义如下:UIActionSheet ...

  2. ARM7ldr指令与ldr伪指令

    ldr伪指令的第二个操作数之前有个=,意思是第一个操作书 = 第二个操作数,相当明了 核心就在于对于用.word指令在.text段里另外定义一段内存,用ldr r0,[pc + x(可以算出.text ...

  3. 【POJ】3294 Life Forms

    后缀数组. /* 3294 */ #include <iostream> #include <sstream> #include <string> #include ...

  4. Android开发框架之xUtils学习

    1.一个非作者弄的xUtils API文档: http://xutilsapi.oschina.mopaas.com/overview-summary.html 2.使用xUtils用户的一些博客文档 ...

  5. poj 1753 Flip Game 枚举(bfs+状态压缩)

    题目:http://poj.org/problem?id=1753 因为粗心错了好多次……,尤其是把1<<15当成了65535: 参考博客:http://www.cnblogs.com/k ...

  6. 反编译.net dll

    自己公司的程序,年代久了,没有源代码,修改一些小地方,只能反编译,还好当时没有混淆. 先ildasm 反编译. 删除   .publickey = ( ) 这段,去原来签名. 然后再用找要改的IL,这 ...

  7. 嵌入式Linux系统运行流程图

    /************************************************************************ * 嵌入式Linux系统运行流程图 * 说明: * ...

  8. JDBC基础教程

    本文实例讲述了JDBC基础知识与技巧.分享给大家供大家参考.具体分析如下: 1.什么是JDBC? 通俗来讲JDBC技术就是通过java程序来发送SQL语句到数据库,数据库收到SQL语句后执行,把结果返 ...

  9. DataTable 分页

    #region DataTable 分页 /// <summary> /// Datatable 分页 /// </summary> /// <param name=&q ...

  10. jvm常量池 vsv为什么1000 == 1000返回为False,而100 == 100会返回为True?

    在jvm规范中,每个类型都有自己的常量池.常量池是某类型所用常量的一个有序集合,包括直接常量(基本类型,String)和对其他类型.字段.方法的符号引用.之所以是符号引用而不是像c语言那样,编译时直接 ...