初学Android,使用Drawable资源之使用ShapeDrawa

系统 1409 0

ShapeDrawable比较简单,用来定义一个基本几何图形,XML的根元素是<shape.../>

下面定义三个shape资源

my_shape_1.xml

 

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" >
    <!-- 设置填充颜色 -->
    <solid android:color="#fff"/>
    <!-- 设置四周的内边距 -->
    <padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp"/>
    <!-- 设置边框 -->
    <stroke android:width="3dip" android:color="#ff0"/>
</shape>
  

my_shape_2.xml

 

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" >
    <!-- 定义填充渐变颜色 -->
    <gradient 
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>
    <!-- 设置内填充 -->
    <padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp"/>
    <!-- 设置圆角矩形 -->
    <corners android:radius="8dp"/>
</shape>
  

my_shape_3.xml

 

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" >
    <!-- 定义填充渐变颜色 -->
    <gradient android:startColor="#ff0"
        android:endColor="#00f"
        android:angle="45"
        android:type="sweep"/>
    <!-- 设置内填充 -->
    <padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp"/>
    <!-- 设置圆角矩形 -->
    <padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp"/>
    <!-- 设置圆角矩形 -->
    <corners android:radius="8dp"/>
</shape>
  

主界面的三个EditBox的背景分别使用上前面定义的三个shape

 

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:background="@drawable/my_shape_1">

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:background="@drawable/my_shape_2"/>

    <EditText
        android:id="@+id/editText3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:background="@drawable/my_shape_3"/>

</LinearLayout>
  

运行效果如下

初学Android,使用Drawable资源之使用ShapeDrawable资源(十五)
这样的效果看起来怪怪的,文本框的背景被弄的乱七八糟了


初学Android,使用Drawable资源之使用ShapeDrawable资源(十五)


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论