天天看點

Android layer-list(3)



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

繼續閱讀