Android Style.xml的应用详解及代码实现
Style.xml的妙用
Style.xml之于Android犹如css之于Jsp
妙用
<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns: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>
这样的布局文件是很正常的。但是不如这样好
<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns: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中添加这些代码即可
<stylename="all_fill"> <itemname="android:layout_width">fill_parent</item> <itemname="android:layout_height">fill_parent</item> </style> <stylename="all_match"> <itemname="android:layout_width">match_content</item> <itemname="android:layout_height">match_content</item> </style> <stylename="width_fill"> <itemname="android:layout_width">fill_parent</item> <itemname="android:layout_height">match_content</item> </style> <stylename="height_fill"> <itemname="android:layout_width">match_content</item> <itemname="android:layout_height">fill_parent</item> </style>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
热门推荐
10 同事换单位简短祝福语
11 谢谢朋友的祝福语简短
12 立秋节气简短祝福语
13 新房祝福语简短10字
14 长辈新年祝福语大全简短
15 新年给大家简短祝福语
16 生日祝福语简短独特姑姑
17 芭比的婚礼祝福语简短
18 邀请新人祝福语简短英文