【android】shape的使用
例子:XML 文件保存在 res/drawable/gradient_box.xml:
<?xml version="1.0" encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<paddingandroid:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp"/>
<cornersandroid:radius="8dp"/>
</shape>
下面这个 XML 把shape应用到view:
<TextView
android:background="@drawable/gradient_box"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
在程序代码里获取shape,应用到view
Resources res =getResources();
Drawable shape = res.getDrawable(R.drawable.gradient_box); TextView tv =(TextView)findViewByID(R.id.textview);
tv.setBackground(shape);
例子
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 渐变 -->
<!-- 详细内容 http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape -->
<gradient
android:startColor="#0000ff"
android:endColor="#00bfff"
android:angle="45"
android:centerX="0.5"/>
<!-- 圆角 -->
<corners
android:radius="8dp"/>
<!-- 外边间距 -->
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<!-- 描边 -->
<stroke android:width="2dp"
android:color="#dcdcdc"
android:dashWidth="5dp"
android:dashGap="0dp" />
<!-- dashgap 表示间隔 有了间隔就成了虚线 --> </shape>
【android】shape的使用的更多相关文章
- android shape使用总结
今天使用到shape,这个里面有很多属性,在这里我记录一下各个属性的使用的情况以及所代表的意思 <?xml version="1.0" encoding="utf- ...
- android:shape
android:shape=["rectangle" | "oval" | "line" | "ring"] shape ...
- Android shape的使用(圆角矩形)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- android shape详解
shape--> shape属性: rectangle: 矩形,默认的形状,可以画出直角矩形.圆角矩形.弧形等 solid: 设置形状填充的颜色,只有android:color一个属性 andr ...
- android shape(如自定义Button)
Shape 前言:有时候会去自己去画一些Button的样式来展现在UI当中,其中主要用到的就是Shape 先来看一段代码: <?xml version="1.0" encod ...
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看 api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...
- Android Shape画圆,矩形
画圆环代码如下: 画圆环,外边的边界宽度大一点即可: <?xml version="1.0" encoding="utf-8"?> <shap ...
- ANDROID SHAPE画圆形背景_ANDROID实现角标布局
ANDROID SHAPE画圆形背景_ANDROID实现角标布局 <?xml version="1.0" encoding="UTF-8"?> &l ...
- android shape总结 和控制的风格定制
1:shape总结 1):shape文件是放置在drawable文件下的.res/drawable/filename.xml. 2):shape类型:android:shape. 一共同拥有四种:re ...
- [转]Android Shape渲染的使用(经典,学习研究不后悔)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mzh3344258.blog.51cto.com/1823534/1215749 ...
随机推荐
- To Java程序员:切勿用普通for循环遍历LinkedList(转)
ArrayList与LinkedList的普通for循环遍历 对于大部分Java程序员朋友们来说,可能平时使用得最多的List就是ArrayList,对于ArrayList的遍历,一般用如下写法: p ...
- ubuntu nfs server config
(1)#sudo apt-get install nfs-kernel-server 打开/etc/exports文件,在末尾加入: /home/hyq *(rw,sync,no_root_squas ...
- Excel分类汇总
版本:2016,数据来源:我要自学网,曾贤志老师 1.首先,要进行分类,在进行汇总, 如对日期进行汇总的话: 如果对品名进行汇总的话 2.光标要定在数据源,在选择分类字段(包含项目比如品名 ...
- IDEA中遇到的gradle问题:unindexed remote maven repositories found
环境公司提供的IDEA,版本为16.3. 前端环境为react.版本控制使用gradle,后端语言使用kotlin. 在项目的依赖导入过程中出现了如下问题: unindexed remote mave ...
- UITableView常见用法以及注意细节
UITableView用途广泛,而且多样化,其中有一些不太常用,用到的话需要去查资料,今天边用边记录下来 *第一发:UITableViewCell 分割线 1. 分割线样式 [self.tableVi ...
- 安装部署ELK系统监控Azure China的NSG和WAF Log
ELK是一个开源的产品,其官网是:https://www.elastic.co/ ELK主要保护三个产品: Elasticsearch:是基于 JSON 的分布式搜索和分析引擎,专为实现水平扩展.高可 ...
- laravel config文件的使用
好多东西 由于许多地方都要使用与将来可能发生更改 我们需要把它提取出来 作为配置文件来使用 这样将来要修改的时候 只需要修改一处即可 学习源头: https://blog.csdn.net/linyu ...
- svn-clearup 报错的处理(Cleanup failed to process the following paths...)
在使用 svn 客户端执行操作失败后,执行 Clean up 操作也报错:Cleanup failed to process the following paths... ,一直不知道是什么原因.通常 ...
- Django基础(二)—— models
六:Models示例 Django本身提供了非常强大易使用的ORM组件,并且支持多种数据库. 配置连接数据文件 在自己创建的project 目录下编辑settings.py DATABASES = { ...
- HAproxy+Mycat
haproxy+mycat搭建haproxy server 10.0.1.134mycat server 10.0.1.134,10.0.1.135mysql master 10.0.1.134mys ...