Android layer-list(3)
在附录文章3、4的基础上,就Android layer-list再写一个较为复杂的应用。
先写布局文件,该布局涉及到LinearLayoutCompat,关于LinearLayoutCompat参看附录文章5。
布局文件activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_light"
tools:context="zhangphil.demo.MainActivity">
<android.support.v7.widget.LinearLayoutCompat xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dip"
android:background="@drawable/layer_list"
android:orientation="vertical"
app:divider="@drawable/shape"
app:dividerPadding="50dip"
app:showDividers="middle">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="zhang phil @csdn" />
</android.support.v7.widget.LinearLayoutCompat>
</RelativeLayout>
其中activity_main.xml中的LinearLayoutCompat涉及到了添加分割线,需要再写一个shape文件,drawable/shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/darker_gray" />
<!-- 分割线的高度 -->
<size android:height="2dip" />
</shape>
drawable/layer_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners
android:bottomLeftRadius="20dip"
android:bottomRightRadius="20dip"
android:topLeftRadius="20dip"
android:topRightRadius="20dip" />
<solid android:color="@android:color/background_light" />
<stroke
android:width="2dip"
android:color="@android:color/darker_gray" />
</shape>
</item>
<item android:drawable="@mipmap/ic_launcher"></item>
</layer-list>
代码运行结果:
附录文章:
1,《Android AnimationDrawable动画与APP启动引导页面》链接地址:http://blog.csdn.net/zhangphil/article/details/47416915
2,《Android ImageView的setImageLevel和level-list使用简介》链接地址:http://blog.csdn.net/zhangphil/article/details/48936209
3,《Android layer-list(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51720924
4,《Android layer-list:联合shape(2)》链接地址:http://blog.csdn.net/zhangphil/article/details/51721283
5,《Android Material Design :LinearLayoutCompat添加分割线divider》链接地址:http://blog.csdn.net/zhangphil/article/details/48899585