一 , 整体布局
<?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:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="测试通过了"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/line_division"
android:text="测试通过了2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/layer_list_test"
android:text="测试通过3"/>
</LinearLayout>
二,给view添加 gap 背景 (对应@drawable/line_division)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="2dp"
android:color="@color/button_normal_color"
android:dashGap="2dp"
android:dashWidth="6dp"/>
<corners android:radius="4dp"/>
<padding
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp"/>
</shape>
三,layer-list 的妙用 (对应@drawable/layer_list_test)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape> <!-- 第一层的颜色为蓝色 -->
<solid android:color="@color/colorAccent"/>
</shape>
</item>
<item android:bottom="2dp">
<shape> <!-- 第一层的颜色为蓝色 -->
<solid android:color="@color/color_captcha_loading"/>
</shape>
</item>
</layer-list>
四,效果图
本文介绍了如何使用XML定义Android应用的界面布局,并演示了三种不同的背景Drawable资源制作方法:整体布局设计、带间隔线的视图背景及多层颜色组合。
477

被折叠的 条评论
为什么被折叠?



