Android中shape的基本使用

shape用于设定形状,可以在selector,layout等里面使用,点击效果神马的我们可以不需要UI的切图,自己直接使用shape搞定,比较方便快捷。 新建一个shape.xml默认为矩形,可以通过android:shape=""来设置具体的形状,有这么四种:rectangle
矩形,oval 椭圆形,line 线,ring 环形。shape有6个子标签,各属性如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- 圆角 -->
    <corners
        android:bottomLeftRadius="8dip"
        android:bottomRightRadius="8dip"
        android:radius="5dip"
        android:topLeftRadius="8dip"
        android:topRightRadius="8dip" />
    <!-- 颜色渐变 -->
    <gradient
        android:angle="45"
        android:centerColor="@android:color/black"
        android:endColor="@android:color/black"
        android:startColor="@android:color/white"
        android:type="linear" />
    <!-- 尺寸大小 -->
    <size
        android:height="28dip"
        android:width="48dip" />
    <!-- 描边 -->
    <stroke
        android:dashGap="2dp"
        android:dashWidth="1dp"
        android:width="1dip"
        android:color="@color/red" />
    <!-- 边距 -->
    <padding
        android:bottom="5dip"
        android:left="5dip"
        android:right="5dip"
        android:top="3dip" />
    <!-- 填充 -->
    <solid android:color="@color/slateblue" />

</shape>

填充:设置填充的颜色

间隔:设置四个方向上的间隔

大小:设置大小

圆角:同时设置五个属性,则Radius属性无效

android:Radius="20dp"                           设置四个角的半径

android:topLeftRadius="20dp"              设置左上角的半径

android:topRightRadius="20dp"           设置右上角的半径

android:bottomLeftRadius="20dp"      设置右下角的半径

android:bottomRightRadius="20dp"    设置左下角的半径

描边:dashWidth和dashGap属性,只要其中一个设置为0dp,则边框为实现边框

android:width="20dp"                               设置边边的宽度

android:color="@android:color/black"  设置边边的颜色

android:dashWidth="2dp"                         设置虚线的宽度

android:dashGap="20dp"                          设置虚线的间隔宽度

渐变:当设置填充颜色后,无渐变效果。angle的值必须是45的倍数(包括0),仅在type="linear"有效,不然会报错。android:useLevel 这个属性不知道有什么用。

时间: 2024-08-18 08:31:55

Android中shape的基本使用的相关文章

Android中shape属性详解

一.简单使用 刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标签怎么用. 1.新建shape文件 首先在res/drawable文件夹下,新建一个文件,命名为:shape_radius.xml 内容是这样的:(先不需要理解,先看shape怎么用) [html] view plaincopyprint? <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="ht

Android中shape中的属性大全

Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码: <shape> <!-- 实心 --> <solid android:color="#ff9d77"/> <!-- 渐变 --> <gradient android:startColor="#ff8c00" android:endColor="#FFFFFF

Android中shape的使用(转)

http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码:        <shape>            <!-- 实心 -->            <solid android:color="#ff9d77"/>            <!-- 渐变 --&

Android中shape的使用 (转载)

转自:http://blog.csdn.net/ekeuy/article/details/12349853 在看很多开源代码中都使用到了shape,我看代码的时候一般都一带而过了,没有仔细去研究,这几天刚好有空就顺带详细了解一下,在学习的过程中参考了官方文档和网上的示例代码,本文后面会附上测试代码. Android应用中使用shape的步骤是这样子的,(1)在res/drawable下定义一个xml文件用于定义shape:(2)在代码中或者在xml文件中引用这个文件就可以看到效果了.下面开始介

android中shape 的使用

android 开发中 对于 shape 和 selector的使用,一直都不是很熟练, 记录一下.便于以后参考. 举个项目中例子图 对于上面的2个radiobutton ,背景我们可以让美工做一个.9图来实现. 但是最后还是自己用shape 搞一下. 按钮布局如下: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:la

android中shape的属性

<shape> <!– 实心 –> <solid android:color=”#ff9d77″/> <!– 渐变 –> <gradient android:startColor=”#ff8c00″ android:endColor=”#FFFFFF” android:angle=”270″ /> <!– 描边 –> <stroke android:width=”2dp” android:color=”#dcdcdc” />

转 Android中shape中的属性大全

<shape>            <!-- 实心 -->            <solid android:color="#ff9d77"/>            <!-- 渐变 -->            <gradient                android:startColor="#ff8c00"                android:endColor="#FFFFFF

Android中Shape的使用

先看一下文档对Shape Drawable的描述: Shape Drawable An XML file that defines a geometric shape, including colors and gradients.一个定义几何形状的XML文件,包括颜色和渐变. 创建一个ShpeDrawable对象 用Android:background="@drawable/xxx.xml"或相应的Java代码引用,Shape Drawable说白了就是可自定义的多样化的背景. 现在

Android中使用shape来定义控件

本文章转接于:http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码:        <shape>            <!-- 实心 -->            <solid android:color="#ff9d77"/>            <!--