位置: 编程技术 - 正文

Android开发:shape和selector和layer-list的(详细说明)(qt Android开发)

编辑:rootadmin

推荐整理分享Android开发:shape和selector和layer-list的(详细说明)(qt Android开发),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:Android开发工具,Android开发者网站,Android开发者网站,qt Android开发,qt Android开发,Android开发者网站,qt Android开发,Android开发者,内容如对您有帮助,希望把文章链接给更多的朋友!

<shape>和<selector>在Android UI设计中经常用到。比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到<shape>和<selector>。可以这样说,<shape>和<selector>在美化控件中的作用是至关重要。

在看这篇文章之前,可以看下这个小例子:镂空按钮的实现

1.Shape简介

作用:XML中定义的几何形状

位置:res/drawable/文件的名称.xml

使用的方法:

Java代码中:R.drawable.文件的名称

XML中:Android:background="@drawable/文件的名称"

属性:

<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"]

其中rectagle矩形,oval椭圆,line水平直线,ring环形

<shape>中子节点的常用属性:

<gradient> 渐变

Android:startColor

起始颜色

Android:endColor

结束颜色

Android:angle

渐变角度,0从左到右,表示从下到上,数&#;为的整数倍,默认为0;

Android:type

渐变的样式 liner线性渐变 radial环形渐变 sweep

<solid > 填充

Android:color

填充的颜色

<stroke >描边

Android:width

描边的宽度

Android:color

描边的颜色

Android:dashWidth

表示'-'横线的宽度

Android:dashGap

表示'-'横线之间的距离

<corners >圆角

Android:radius

圆角的半径 &#;越大角越圆

Android开发:shape和selector和layer-list的(详细说明)(qt Android开发)

Android:topRightRadius

右上圆角半径

Android:bottomLeftRadius

右下圆角角半径

Android:topLeftRadius

左上圆角半径

Android:bottomRightRadius

左下圆角半径

<padding >填充

android:bottom="1.0dip"

底部填充

android:left="1.0dip"

左边填充

android:right="1.0dip"

右边填充

android:top="0.0dip"

上面填充

2.Selector简介

根据不同的选定状态来定义不同的现实效果

分为四大属性:

android:state_selected 是选中

android:state_focused 是获得焦点

android:state_pressed 是点击

android:state_enabled 是设置是否响应事件,指所有事件

另:

android:state_window_focused 默认时的背景图片

引用位置:res/drawable/文件的名称.xml

使用的方法:Java代码中:R.drawable.文件的名称

XML中:Android:background="@drawable/文件的名称"

[html] view plaincopy<?xml version="1.0" encoding="utf-8" ?> <selector xmlns:Android=" <!-- 默认时的背景图片--> <item Android:drawable="@drawable/pic1" /> <!-- 没有焦点时的背景图片 --> <item Android:state_window_focused="false" android:drawable="@drawable/pic_blue" /> <!-- 非触摸模式下获得焦点并单击时的背景图片 --> <item Android:state_focused="true" android:state_pressed="true" android:drawable= "@drawable/pic_red" /> <!-- 触摸模式下单击时的背景图片--> <item Android:state_focused="false" Android:state_pressed="true" Android:drawable="@drawable/pic_pink" /> <!--选中时的图片背景--> <item Android:state_selected="true" android:drawable="@drawable/pic_orange" /> <!--获得焦点时的图片背景--> <item Android:state_focused="true" Android:drawable="@drawable/pic_green" /> </selector> 3.layer-list 简介:将多个图片或上面两种效果按照顺序层叠起来例子:[html] view plaincopy<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android=" <item> <bitmap android:src="@drawable/android_red" android:gravity="center" /> </item> <item android:top="dp" android:left="dp"> <bitmap android:src="@drawable/android_green" android:gravity="center" /> </item> <item android:top="dp" android:left="dp"> <bitmap android:src="@drawable/android_blue" android:gravity="center" /> </item> </layer-list> [html] view plaincopy<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/layers" /> 效果图:

4.最后

以上三个标签可以揉合到一块儿来使用,所要实现的效果就是上面三种标签的说明,比如下面这个例子:

[html] view plaincopy<selector xmlns:android=" <item android:state_pressed="true"> <layer-list> <item android:bottom="8.0dip"> <shape> <solid android:color="#ffaaaaaa" /> </shape> </item> <item> <shape> <corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" /> <solid android:color="#ffaaaaaa" /> <padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" /> </shape> </item> <item> <shape> <corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" /> <solid android:color="@color/setting_item_bgcolor_press" /> </shape> </item> </layer-list> </item> <item> <layer-list> <item android:bottom="8.0dip"> <shape> <solid android:color="#ffaaaaaa" /> </shape> </item> <item> <shape> <corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" /> <solid android:color="#ffaaaaaa" /> <padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" /> </shape> </item> <item> <shape> <corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" /> <solid android:color="@color/setting_item_bgcolor" /> </shape> </item> </layer-list> </item> </selector>

Android Path和PathMeasure类的使用之获取圆弧上的坐标值 问题:已知图中的中心圆点在屏幕上的坐标为(x,y),分别求出点1、2、3、4的坐标!解决方法:可以利用Android的SDK自带类android.graphics.Path和android.graphics.Pa

EditText获取焦点不自动弹出键盘设置 EditText获取焦点不自动弹出键盘设置带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘如果不想自动弹出键盘,有两种方法:方法一:

Android Volley完全解析(一),初识Volley的基本用法 1.Volley简介我们平时在开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据。Android系统

标签: qt Android开发

本文链接地址:https://www.jiuchutong.com/biancheng/386754.html 转载请保留说明!

上一篇:android上开源项目、酷炫的交互动画和视觉效果(android开源小项目)

下一篇:Android Path和PathMeasure类的使用之获取圆弧上的坐标值

  • 结转增值税会计摘要
  • 个人所得税缴纳标准税率表
  • 文化建设费征收依据
  • 出租车发票可以重新打印吗
  • 应收款时间太长怎么处理
  • 已发货未收钱会计分录
  • 个人往对公账户上存款怎么存
  • 单位购牙膏牙刷卫生纸怎么做账
  • 跨期两年的发票怎么处理
  • 内涵报酬率和必要投资报酬率
  • 所得税汇算清缴分录怎么做
  • 商场返券活动300返220
  • 废弃土地的使用年限
  • 企业所得税营业收入包括什么
  • 建安业一般纳税人是清包工是什么意思
  • 农业企业发包给人种植要交纳个税吗?
  • 报废固定资产增值税税率
  • 策划费收费标准
  • 金税盘可以异地使用吗
  • 土地作价入股土地如何过户
  • 应交税费待抵扣进项税额是什么科目
  • 零申报做账怎么做
  • 境外代扣代缴所得税
  • 零元股权转让会亏本吗
  • 安装支付设备工作怎么样
  • win11进入黑屏
  • ie增强的安全配置已启用上不了网
  • 金融保险属于什么行业
  • 企业投资收益如何做账
  • smartypig
  • i911900k与10900k
  • 前端lru
  • mac配置node环境
  • 部门活动经费怎么算
  • 扣除发票
  • 小企业会计准则
  • 水利建设基金计税依据
  • 凭证怎么记账
  • php实现的功能
  • 深度卷积神经网络基本结构
  • vue2和vue3的区别大么
  • php遍历数组使用的是
  • wordpress文章主题
  • 预付卡销售和充值计入什么费用
  • 房地产企业建筑成本
  • 固定资产处置收入增值税税率
  • 子公司计入长期股权投资吗
  • 制造费用月末一般有余额吗
  • php压缩文件怎么打开
  • 织梦怎么改网站主页
  • 小规模简易征收最新政策2020
  • 工程结算成本和主营业务成本一样吗
  • 记帐时借方是什么意思
  • 子公司注销合并报表少数股东权益的处理
  • 代扣代缴增值税要交附加税吗
  • 小规模减免的增值税要交所得税吗
  • 企业办税人员如何实名认证
  • 报废周转材料应负担的成本差异
  • 销售包装物计入其他应收款吗
  • 道路施工企业的上级监管部门是谁
  • 工会经费的使用应当依法接受国家的监督
  • 党委经费是国家政府出吗?
  • 买电脑能砍多少
  • 法人能去税务局开个人发票吗
  • 律师事务所日语助理
  • 临时人员是什么
  • 新准则会计科目解释
  • 进项税额转出怎么操作
  • Linux下MySQL 5.5/5.6的修改字符集编码为UTF8的方法
  • subss
  • windows7桌面右击
  • win7哪些系统文件可以删除
  • 怎么删除listview条目
  • js获取url的html
  • perl获取文件名
  • python简单编码
  • javascript面向对象编程指南第三版
  • 怎么看网页的编码格式
  • 新疆12366网上办税
  • 青羊名字由来
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设