Android Style.xml的应用详解及代码实现
更新时间:2016年10月26日 10:17:15 投稿:lqh
这篇文章主要介绍了Android Style.xml的应用详解及代码实现的相关资料,需要的朋友可以参考下
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常用布局(FrameLayout、LinearLayout、RelativeLayout)详解
这篇文章主要为大家详细介绍了Android常用布局FrameLayout、LinearLayout、RelativeLayout,感兴趣的小伙伴们可以参考一下2016-06-06
Android使用PowerImageView实现播放强大的ImageView动画效果
今天我们就来编写一个PowerImageView控件,让它既能支持ImageView控件原生的所有功能,同时还可以播放GIF图片2018-05-05
Kotlin字节码层探究构造函数与成员变量和init代码块执行顺序
这篇文章主要介绍了字节码层Kotlin构造函数与成员变量和init代码块执行顺序,kotlin里面的构造函数分为主构造函数和次构造函数。主构造函数只能有一个,次构造函数个数不限制,可以有一个或者多个2022-11-11
Android ReboundScrollView仿IOS拖拽回弹效果
这篇文章主要为大家详细介绍了Android ReboundScrollView仿IOS拖拽回弹效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-11-11


最新评论