- 浏览: 173392 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
hety163:
socket并不一定是长连接吧。。。
【转】关于socket长连接的心跳包 -
u013490012:
楼主,这个加阴影不是很清楚.我按照文章介绍的,程序出错啊
Android自定义Shape 加上阴影shadow之方法 -
cz2861856:
很好的文章!
Android自定义Shape 加上阴影shadow之方法 -
ezfantasy:
好文,转走了
Android 使用xliff 格式化字符串 -
songfantasy:
ericbaner 写道Android官方blog:http: ...
Android HTTP Clients使用选择介绍
Android支持自定义Shape, 以画出需要的形状,可以作为TextView, EditText, Button的背景drawable资源。Shape很简单,就是一个XML文件,SDK文档里描述其格式如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > <corners android:radius="integer" android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer" /> <gradient android:angle="integer" android:centerX="integer" android:centerY="integer" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" | "radial" | "sweep"] android:usesLevel=["true" | "false"] /> <padding android:left="integer" android:top="integer" android:right="integer" android:bottom="integer" /> <size android:width="integer" android:height="integer" /> <solid android:color="color" /> <stroke android:width="integer" android:color="color" android:dashWidth="integer" android:dashGap="integer" /> </shape>
其支持的属性没有shadow, 做Web前端开发的同学写CSS可以很方便地加一个shadow属性值,如何给Android Shape加一个shadow,以得到类似的效果呢?
答案是使用layer-list ! 直接上代码如下:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#792a03" /> <corners android:radius="19dp" /> </shape> </item> <item android:top="1px"> <shape android:shape="rectangle"> <gradient android:startColor="#ffdb8f" android:endColor="#ffdb8f" android:angle="270" /> <padding android:left="5dp" android:top="3dp" android:right="5dp" android:bottom="3dp" /> <corners android:radius="20dp" /> </shape> </item> </layer-list>
将以上xml存成btn_test, 放到res/drawable/目录下。 将该drawable xml设为一个TextView的backgroiund,
<TextView android:background="@drawable/btn_test" android:layout_marginTop="20dip" android:layout_marginLeft="5dip" android:textColor="#792a03" android:text="1天2小时14分20秒" android:layout_width="wrap_content" android:layout_height="wrap_content" />
其效果如下图所示:
关于layer-list的进一步解释见SDK文档,如下:
Layer List
A LayerDrawable
is a drawable object
that manages an array of other drawables. Each drawable in the list is drawn in the order of the
list—the last drawable in the list is drawn on top.
Each drawable is represented by an <item>
element inside a single <layer-list>
element.
res/drawable/filename
.xml
The filename is used as the resource ID.
LayerDrawable
.R.drawable.filename
In XML:
@[package
:]drawable/filename
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@[package:]drawable/drawable_resource" android:id="@[+][package:]id/resource_name" android:top="dimension" android:right="dimension" android:bottom="dimension" android:left="dimension" /> </layer-list>
<layer-list>
<item>
elements.
attributes:
xmlns:android
"http://schemas.android.com/apk/res/android"
.
<item>
<selector>
element. Accepts child <bitmap>
elements.
attributes:
android:drawable
android:id
"@+id/name
"
. The plus symbol indicates that this should be created as a new
ID. You can use this identifier to
retrieve and modify the drawable with View.findViewById()
or Activity.findViewById()
.android:top
android:right
android:bottom
android:left
All drawable items are scaled to fit the size of the containing View, by default. Thus,
placing your images in a layer list at different positions might increase the size of the View and
some images scale as appropriate. To avoid
scaling items in the list, use a <bitmap>
element inside the <item>
element to specify the drawable and define the gravity to something that does not
scale, such as "center"
. For example, the following <item>
defines an item
that scales to fit its container View:
<item android:drawable="@drawable/image" />
To avoid scaling, the following example uses a <bitmap>
element with centered
gravity:
<item> <bitmap android:src="@drawable/image" android:gravity="center" /> </item>
res/drawable/layers.xml
:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <bitmap android:src="@drawable/android_red" android:gravity="center" /> </item> <item android:top="10dp" android:left="10dp"> <bitmap android:src="@drawable/android_green" android:gravity="center" /> </item> <item android:top="20dp" android:left="20dp"> <bitmap android:src="@drawable/android_blue" android:gravity="center" /> </item> </layer-list>
Notice that this example uses a nested <bitmap>
element to define the drawable
resource for each item with a "center" gravity. This ensures that none of the images are scaled to
fit the size of the container, due to resizing caused by the offset images.
This layout XML applies the drawable to a View:
This layout XML applies the drawable to a View:
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/layers" />
The result is a stack of increasingly offset images:
发表评论
-
【转】eclipse 找不到Courier New 样式解决方法
2013-07-13 17:24 1000之前有朋友问到说eclipse3.7,以及以后版本(貌似直 ... -
【转】Android使用ant对项目进行编译签名优化打包
2013-05-14 10:42 1032Android本身是支持ant打包项目的,并且SDK中自带一个 ... -
Android一些常用的颜色值
2013-05-09 17:30 1072一些常用的颜色值: <?xml version= ... -
【转】Android jar resource 资源文件的获取
2013-04-17 23:56 4428jar引用的资源文件必须放在assets文件夹中,并且布局文 ... -
【转】Android导出jar library时资源resource id获取的问题
2013-04-17 23:50 4199当需要把一个Android导出为jar包时,如果里面有用 ... -
【转】Android类库打包方法探究
2013-04-17 10:51 829开发Android应用的时候 ... -
【转】Android编程之解决android-support-v4打包问题
2013-03-11 19:21 1065如果工程引入了android-s ... -
【转】Android NIO Socket编程
2013-03-05 20:45 1624根据前两周写的关于Socket编程的网络通信的代码,现在对有 ... -
【转】关于socket长连接的心跳包
2013-03-05 17:39 2257出于最近对im研究的兴趣,看到smack里有个30s发送一个 ... -
【转】java nio对OP_WRITE的处理解决网速慢的连接
2013-03-05 15:20 200617.3.1 如何处理慢速的 ... -
【转】Java 加密解密基础
2013-01-24 10:54 995Java 加密解密基础 密码学是研究编制密码和破译密码的 ... -
【转】RSA选用小公钥指数(e=3)真的不安全吗?
2013-01-24 10:04 2880引言现有的大部分RSA算法实现都遵循PKCS#1 v2.1/ ... -
【转】RSA加密的填充模式
2013-01-24 10:02 4924跟DES,AES一样, RSA也是一个块加密算法( bloc ... -
【转载】RSA数字签名与加密、解密间的关系
2013-01-22 22:02 1179转载提及RSA,大家 ... -
ubuntu 10.04LTS安装sun java6 jdk问题解决
2013-01-07 18:01 1209unbuntu10.04安装java6问题 Packag ... -
异步线程干活和回调 的设计模式
2012-12-04 12:24 0老板要干事情通过开启代理线程进行,老板有一个回调函数代理(苦力 ... -
如何成为JAVA大牛?
2012-12-04 11:19 0如何成为JAVA大牛? 首先要有目标的去学习,我给 ... -
经典JAVA面试题
2012-11-29 10:26 0基础: 1. JAVA的数据类型可以分成哪两类? 原始 ... -
接口与抽象类
2012-11-27 23:22 1028以下为选摘自网络,罗 ... -
android 使用Application保存全局变量
2012-10-29 17:37 1704三个步骤,将全局对象保存在Application进程。 ...
相关推荐
本文实例讲述了Android编程使用自定义shape实现shadow阴影效果的方法。分享给大家供大家参考,具体如下: 直接上xml文件, 并且附上相应的解析: <?xml version=1.0 encoding=utf-8?> <selector xmlns:android...
Android中使用Shape自定义形状
Android自定义阴影的Demo,颜色,圆角,比自定义shape更逼真,任何版本都可使用
Android自定义矩形及selector、shape的使用Android自定义矩形及selector、shape的使用
主要介绍了android shape的使用及渐变色、分割线、边框、半透明阴影,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
1.实现阴影或模糊边效果方式: 2.通过shape来实现,具体是通过layer-list 多层叠放的方式实现的 <?xml version=1.0 encoding=utf-8?> <layer-list xmlns:android=...
android-shape-imageview - 图片圆角、三角、五角、圆形、多角
android-shape-imageview自定义形状的 imageview.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
本文主要介绍自定义shape(定义矩形、定义边框颜色、定义圆角弧度),具体代码如下,感兴趣的各位可以参考下哈,希望对大家有所帮助
Android-shape标签的使用,让我们的界面更加高大上档次
本文主要记录Android控件设置阴影 给控件设置阴影,会使得界面元素更好看一写,google 给我们提供了一个现成的控CardView,可以将CardView看做是FrameLayout在自身之上添加了圆角和阴影效果 本文是使用给控件设置...
本篇文章主要介绍了Android使用shape绘制阴影图层阴影效果示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Custom shaped layout for Android 自定义形状布局 Features Clip layout and its childview. 2 way to set shape. Also custom shape by implement ShapeModel. Dependency Add this in your build.gradle file ...
android 用shape画出来的颜色做背景时,动态的改变它的颜色属性。
自定义阴影效果控件 06.如何使用该阴影控件 07.在recyclerView中使用注意点 01.阴影效果有哪些实现方式 阴影效果有哪些实现方式 第一种:使用CardView,但是不能设置阴影颜色 第二种:采用shape叠加,存在后期...
利用shape优化android UI
android 代码实现shape GradientDrawable
前言 说实话当第一次看到这个需求的时候,第一反应就是Canvas只有drawLine方法,并没有drawDashLine方法啊!这咋整啊,难道要我自己做个遍历不断的drawLine?不到1秒,我就放弃这个想法了,因为太恶心...shape xmlns:a