zoukankan      html  css  js  c++  java
  • android学习笔记33——资源ShapeDrawable

    ShapeDrawable

    ShapeDrawable用于定义一个基本的几何图像(如,矩形、圆形、线条.......)。

    定义ShapeDrawable的XML文件的根元素是<shape.../>,该元素可指定如下属性:

    android:shape=["rectangle"|"oval"|"ling"|"ring"]——指定定义那种类型的几何图形。

    实例如下:椭圆、渐变背景的文本框

    drawable资源文件==》
    
    myshape1.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:bottom="7dp"
            android:left="7dp"
            android:right="7dp"
            android:top="7dp" />
        <!-- 设置边框 -->
        <stroke
            android:width="3dip"
            android:color="#ff0" />
    
    </shape>
    
    myshape2.xml==>
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <!-- 定义填充渐变色 angle,角度 -->
        <gradient
            android:angle="45"
            android:endColor="#80FF00FF"
            android:startColor="#FFFF0000" />
        <!-- 设置四周的内边距 -->
        <padding
            android:bottom="7dp"
            android:left="7dp"
            android:right="7dp"
            android:top="7dp" />
        <!-- 设置圆角矩形 -->
        <corners android:radius="8dp" />
    
    </shape>
    
    myshape3.xml==>
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval" >
    
        <!-- 定义填充渐变色 -->
        <gradient
            android:angle="45"
            android:endColor="#00f"
            android:startColor="#ff0"
            android:type="sweep" />
        <!-- 设置四周的内边距 -->
        <padding
            android:bottom="7dp"
            android:left="7dp"
            android:right="7dp"
            android:top="7dp" />
     <!-- 设置圆角矩形 -->
        <corners android:radius="8dp" />
    
    </shape>
    
    布局文件==》
    <LinearLayout 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:orientation="vertical"
        tools:context=".MainActivity" >
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/myshape1" />
    
     <EditText
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@drawable/myshape2" />
    
      <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/myshape3" />
    </LinearLayout>
    

    运行效果:

  • 相关阅读:
    SenCha Touch AJAX跨域
    MS SQL 索引分析
    Tomcat性能优化(二) 启动参数设置
    PLSQL 连接不上64位ORACLE数据库解决办法
    PLSQL 配置连接ORACLE数据库
    Mybatis Batch 批量操作
    [No000014]听说不背单词,考英语会是这种下场-我们为什么必须背单词?
    [No000000]常用软件测试编译环境声明
    [No000013]在Office中关闭自动拼写检查和自动语法检查
    [No000012]编程中浮点数之什么是科学计数法
  • 原文地址:https://www.cnblogs.com/YYkun/p/5848393.html
Copyright © 2011-2022 走看看