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

news/2024/7/8 4:54:54 标签: android, layout, encoding, 图形, xml

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>
运行效果如下


这样的效果看起来怪怪的,文本框的背景被弄的乱七八糟了




http://www.niftyadmin.cn/n/1411412.html

相关文章

基于vue、vue-router、axios的App项目的总结

项目需求 我的项目的github地址&#xff1a; https://github.com/liwudi/VueProject.git 1、基本的登录注册功能 2、主页面的商品展示、商品分类、轮播。购物车的功能、我的订单的功能、用户中心的相关功能。 相关界面的展示 1、登录注册 2、主界面——首页 3、主界…

初学Android,使用Drawable资源之使用ClipDrawable资源(十六)

ClipDrawable代表从其它位图上截取一个"图片片段",XML中的根元素为<clip.../>,截取的方向由clipOrientation控制 下面以一个慢慢展开的图片为例 先定义一个ClipDrawable资源文件my_clip.xml<?xml version"1.0" encoding"utf-8"?> …

PHP日志扩展SeasLog-1.6.0,支持TCP,UDP发送

SeasLog-1.6.0 发布&#xff0c;支持TCP,UDP发送&#xff0c;轻量高效的PHP日志扩展。 改进日志: 此次改进支持appender配置&#xff0c;同时支持File,TCP,UDP三种发送方式。 Fixed issue #90 #92 Date format.Fixed issue #96 Clear memory leaks.Fixed issue #91 Support TCP…

react教程(一)——react优势以及组件、state、props介绍

1、react是什么&#xff1f;它的优势在哪&#xff1f; react是在前端的单页面应用领域中&#xff0c;处于领导地位&#xff01;它使用虚拟DOM和组件化开发的方式&#xff0c;重新定义了前端开发的方式。 如果说react的优势在哪&#xff1f;我认为是这两点&#xff01; 第一点…

初学Android,使用Drawable资源之使用AnimationDrawable资源(十七)

这次学学怎么使用动画资源,AnimationDrawable,同样要定义一个相关的xml动画文件,要放在路径/res/anmi下,当创建一个Android应用时&#xff0c;默认不会创建该文件夹,需要自己手动创建&#xff0e; 动画分为逐帧动画(像电影一样,一张一张的播放)和补间动画(平移,旋转,缩放,位移&…

什么是开源以及我的开源经验

国内的很多软件公司或研究机构对开源的热情仅限于免费的代码&#xff0c;而绝少深度参与开源社区的活动。我们对于开源始终是利用多&#xff0c;而贡献少&#xff0c;从国内发起的有 一定影响力的开源项目如果不是完全没有&#xff0c;恐怕也是凤毛麟角。我们是如此的吝啬&…

React教程(二)——jsx语法、条件渲染、列表渲染

1、JSX 语法 在react中&#xff0c;就是使用jsx的语法&#xff0c;来实现DOM元素的展示。一个基本的jsx语法的react模板如下&#xff1a; <div>{this.props.title}</div> 这种方式的本质是&#xff1a;在html中嵌入js表达式&#xff01;&#xff01; 那到底编译…

初学Android,使用自定义的XML资源(十八)

使用自定义的XML资源&#xff0c;这当然也必须是Android的一个功能,Java开发者可以使用DOM,SAX等多种方式,Android内建了Pull来解析XML 那么我个人觉得在Android中还是使用它的内建解析方法比较好,使用其它方式还要下载它们的Jar包,还是挺麻烦的&#xff0e;同样的,和动画资源一…