Android自定义控件----YluoTextView可以改变Drawable大小颜色的TextView
2016-07-27 20:26
477 查看
在目前的项目中,很多地方都要用TextView.然后要添加图片,就通过drawableTop这种方式来实现.但是,png的实际高度跟通过getIntrinsicWidth和getIntrinsicHeight获取到的高度是有一定的偏差的.所以为了实际效果只能通过代码修改了,一个还好.但是每一个都要去修改的话那么得用多少代码啊. 还有TextView在点击的时候也需要一个按下的效果,平常的话可以通过selector来实现的,但是同理,得写多少个xml文件呢? 平时textView按下的时候一般都是修改一下颜色或者透明度的,为了实现这个效果设计师要多做几套图来.工足量大很多.因此为了解决这些问题,我就写了YluoTextView,直接看效果吧:
第一张是原始的TextView,
后面两张是YluoTextView的效果.
使用代码如下:
用法是不是很简单呢,就需要添加几个设置就可以省下N多功夫了.
项目下载地址在我的github上:https://github.com/yingtianxun/YluoTextView
如果现在的功能还不能满足大家,大家可以自己去修改代码呢.
第一张是原始的TextView,
后面两张是YluoTextView的效果.
使用代码如下:
// 普通的TextView的用法 <TextView android:layout_marginLeft="100dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/e5b" android:text="跑步" android:textColor="#ff959595"/> // YluoTextView的用法 <com.example.yluotextview.YluoTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:layout_marginLeft="100dp" android:drawableTop="@drawable/e5b" android:text="跑步" android:textColor="#ff959595" yluo:create_presseddawable="true" yluo:drawable_height="21dp" yluo:drawable_width="21dp" yluo:pressed_textcolor="#64959595" yluo:use_yluo="true" /> <com.example.yluotextview.YluoTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:layout_marginTop="50dp" android:drawableTop="@drawable/e5b" android:text="跑步" android:textColor="#ff959595" yluo:create_presseddawable="true" yluo:drawable_height="21dp" yluo:drawable_width="21dp" yluo:pressed_textcolor="@android:color/holo_red_dark" yluo:use_yluo="true" />
用法是不是很简单呢,就需要添加几个设置就可以省下N多功夫了.
项目下载地址在我的github上:https://github.com/yingtianxun/YluoTextView
如果现在的功能还不能满足大家,大家可以自己去修改代码呢.
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories