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>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西