Android中shape的使用

原文地址:http://jingyan.baidu.com/article/86112f13513f4127379787b0.html

在看很多开源代码中都使用到了shape,我看代码的时候一般都一带而过了,没有仔细去研究,这几天刚好有空就顺带详细了解一下,在学习的过程中参考了官方文档和网上的示例代码,本文后面会附上测试代码。

方法/步骤

  1. 1

    一、在res/drawable文件夹下创建一个名为gradient_box的xml文件:

     

        xmlns:android="http://schemas.android.com/apk/res/android"

        android:shape="rectangle">

        

       

         

            android:radius="8dp"

            android:topLeftRadius="5dp"

            android:topRightRadius="15dp"

            android:bottomLeftRadius="20dp"

            android:bottomRightRadius="25dp"  

            />

         

         

       

            android:startColor="#FFFF0000"

            android:endColor="#80FF00FF"

            android:angle="45"

            /> 

            

       

         

             android:left="10dp"

             android:top="10dp"

             android:right="10dp"

             android:bottom="10dp"

             />

         

       

       

            android:width="600dp"

            />

        

       

       

            android:color="#ffff9d77"

            />

        

         

         

            android:width="2dp"

            android:color="#dcdcdc"  

            /> 

  2. 2

    二、在窗口布局文件中将步骤一中创建的文件作为TextView的背景:

        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent">

       

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="ShapeTest"

            android:background="@drawable/gradient_box"

            android:textSize="24.0dp"

            android:textColor="@android:color/black"

            />

  3. 3

    三、运行效果展示:

    Android中shape的使用
    END

软件基本信息

你可能感兴趣的:(Android中shape的使用)