我们的应用中,常常有一些统一的组件,这时候应该用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. zoj 3640 Help Me Escape 概率DP

    记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  2. 2013 Multi-University Training Contest 5 Partition

    思路:五边形数定理!!! 五边形数定理是一个由欧拉发现的数学定理,描述欧拉函数展开式的特性.欧拉函数的展开式如下: 亦即 欧拉函数展开后,有些次方项被消去,只留下次方项为1, 2, 5, 7, 12, ...

  3. 李洪强iOS开发之使用CycleScrollView实现轮播图

    01 导入头文件,并且定义CycleScrollView属性 02 初始化,设置frame并且添加到collectionView上 03 调用方法并且设置轮播的图片

  4. [itint5]交替字符串

    http://www.itint5.com/oj/#17 DP.注意曾经把赋值写成了==,结果出错半天. bool isInterleaving(string &str1, string &a ...

  5. CVE爬虫抓取漏洞URL

    String url1="http://www.cnnvd.org.cn/vulnerability/index/vulcode2/tomcat/vulcode/tomcat/cnnvdid ...

  6. 关于捕获键盘信息的processDialogkey方法2--具体应用

    自定义控件里的keydown方法无法捕获所有的按键消息的处理方法1(自定义控件里的keydown方法无法获取的键值如上下左右键等) 处理办法具体如下: 1.首先在自定义控件UserControl1中重 ...

  7. Android-xUtils框架介绍(二)

    昨天对xUtils整体上做了一个简单的介绍,今天咱们就代码码起,真刀实枪的也看看,看看如何快速便捷的把xUtils给集成到大家的项目中去.xUtils中有四大组件可以供我们使用,分别是ViewUtil ...

  8. Java [leetcode 18]4Sum

    问题描述: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d ...

  9. Android开发优化宝典

    I. 网络相关 http头信息带Cache-Control域 确定缓存过期时间 防止重复请求 直接用IP直连,不用域名,策略性跟新本地IP列表. – DNS解析过程耗时在百毫秒左右,并且还有可能存在D ...

  10. ASP.NET MVC中默认Model Binder绑定Action参数为List、Dictionary等集合的实例

    在实际的ASP.NET mvc项目开发中,有时会遇到一个参数是一个List.Dictionary等集合类型的情况,默认的情况ASP.NET MVC框架是怎么为我们绑定ASP.NET MVC的Actio ...