android shape 小笔记

本文介绍了如何使用XML定义Android应用的界面布局,并演示了三种不同的背景Drawable资源制作方法:整体布局设计、带间隔线的视图背景及多层颜色组合。

一 , 整体布局

<?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>

四,效果图

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值