Android Style.xml的应用详解及代码实现
作者:lqh 时间:2022-02-25 00:36:28
Style.xml的妙用
Style.xml之于Android犹如css之于Jsp
妙用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/sensor"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
这样的布局文件是很正常的。但是不如这样好
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/all_match"
android:orientation="vertical" >
<TextView
android:id="@+id/sensor"
style="@style/all_fill" />
</LinearLayout>
省时省力,一眼还能看出是什么布局方式。只需要在Style.xml 中添加 这些代码即可
<style name="all_fill" >
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="all_match" >
<item name="android:layout_width">match_content</item>
<item name="android:layout_height">match_content</item>
</style>
<style name="width_fill" >
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">match_content</item>
</style>
<style name="height_fill" >
<item name="android:layout_width">match_content</item>
<item name="android:layout_height">fill_parent</item>
</style>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
标签:Android,Style.xml
0
投稿
猜你喜欢
Java获取时间打印到控制台代码实例
2022-07-20 22:43:48
java 微信随机红包算法代码实例
2022-12-03 12:29:08
利用Android封装一个有趣的Loading组件
2023-01-07 16:25:28
C++实现图书管理系统
2023-11-03 03:00:35
C#正则表达式匹配HTML中的图片路径,图片地址代码
2023-03-10 16:33:48
Java List分页功能实现代码实例
2022-06-02 13:56:14
Unity实现UI光晕效果(发光效果)
2022-07-08 16:37:41
datatables 带查询条件java服务端分页处理实例
2023-12-24 08:48:16
自定义类加载器以及打破双亲委派模型解析
2023-06-22 22:03:59
SpringBoot向容器注册bean的方法详解
2023-09-02 10:58:22
C#计算两个文件的相对目录算法的实例代码
2022-08-27 10:27:44
浅谈Maven的build生命周期和常用plugin
2022-11-03 01:47:52
Spring中集成Groovy的四种方式(小结)
2023-07-11 16:36:53
Treeview动态添加用户控件传值和取值的实例代码
2021-07-20 11:20:07
Springboot如何通过yml配置文件为静态成员变量赋值
2021-08-03 12:03:17
Java MyBatis本地缓存原理详解
2023-01-30 18:20:36
浅谈MyBatis 如何执行一条 SQL语句
2023-10-17 19:36:03
一篇文章带你入门Java Script
2023-09-12 06:09:24
C#多线程与跨线程访问界面控件的方法
2023-11-25 12:00:29
Android实现简单旋转动画
2023-11-07 09:50:58