scaleType-模拟按钮加文字整天点击效果
2015-08-21 21:26
295 查看
经常碰到这种情况,就是一个按钮下面有文字,我们点击按钮的时候,按钮跟文字的背景都是同时变化的。我们看下下面的效果
点击以后如下
如果想要实现这个方法,网上有很多的方法,主要就是自定义控件,或者是使用textview本身提供的增加drawable方法。这里主要是使用一个偷懒的方法。使用ImageButton 跟 TextView 一起实现。虽然方法很笨,灵活性很差。但至少能实现效果。如下
其中主要就是
的方法
它可以把图片放到控件ImageButton的左上角。然后我们使用padding来调整图片的作用位置。就可实现imageButton 点击区域充满整个父容器了
点击以后如下
如果想要实现这个方法,网上有很多的方法,主要就是自定义控件,或者是使用textview本身提供的增加drawable方法。这里主要是使用一个偷懒的方法。使用ImageButton 跟 TextView 一起实现。虽然方法很笨,灵活性很差。但至少能实现效果。如下
<RelativeLayout android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" > <ImageButton android:id="@+id/ig" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_launcher" android:scaleType="matrix" android:paddingLeft="80dp" android:background="@drawable/select" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="aaaaaaa" android:textColor="#ffffff" android:layout_marginBottom="10dp" android:textSize="30sp" /> </RelativeLayout>
其中主要就是
android:scaleType="matrix"
的方法
它可以把图片放到控件ImageButton的左上角。然后我们使用padding来调整图片的作用位置。就可实现imageButton 点击区域充满整个父容器了
相关文章推荐
- 黑马程序员--Java基础学习(面向对象)第七天
- View和ViewGroup的事件分发机制详解
- hdu5414 CRB and String
- 长链非编码RNA(lncRNA)
- Linux系统管理之十四---服务
- 后端分布式系列:分布式存储-HDFS 架构解析
- 后端分布式系列:分布式存储-HDFS 架构解析
- ShapeDrawable做放大镜效果
- ShapeDrawable做放大镜效果
- shell编程——if条件判断(转)
- java并发编程---如何创建线程以及Thread类的使用
- ShapeDrawable做放大镜效果
- 用 mongodb + elasticsearch 实现中文检索
- 后端分布式系列:分布式存储-HDFS 架构解析
- Android UI设计——EditText控件
- HDFS 架构解析
- 端到段、点到点通信的区别 优缺点
- 组合数专题
- 小点滴——oracle 11g登陆不到控制台https://localhost:1158/em/的解决
- 转载 android权限