CustomDrawableTextView
public class CustomDrawableTextView extends TextView{
//image width、height
private int imageWidth;
private int imageHeight;
private Drawable leftImage;
private Drawable topImage;
private Drawable rightImage;
private Drawable bottomImage;
public CustomDrawableTextView(Context context) {
this(context, null);
}
public CustomDrawableTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomDrawableTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomDrawableTextView,0,0);
int countNum = ta.getIndexCount();
for (int i = 0; i < countNum; i++) {
int attr = ta.getIndex(i);
if (attr == R.styleable.CustomDrawableTextView_leftImage) {
leftImage = ta.getDrawable(attr);
} else if (attr == R.styleable.CustomDrawableTextView_topImage) {
topImage = ta.getDrawable(attr);
} else if (attr == R.styleable.CustomDrawableTextView_rightImage) {
rightImage = ta.getDrawable(attr);
} else if (attr == R.styleable.CustomDrawableTextView_bottomImage) {
bottomImage = ta.getDrawable(attr);
} else if (attr == R.styleable.CustomDrawableTextView_imageWidth) {
imageWidth = ta.getDimensionPixelSize(attr, (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()));
} else if (attr == R.styleable.CustomDrawableTextView_imageHeight) {
imageHeight = ta.getDimensionPixelSize(attr, (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()));
}
}
ta.recycle();
init();
}
/**
* init views
*/
private void init() {
setCompoundDrawablesWithIntrinsicBounds(leftImage,topImage,rightImage,bottomImage);
}
@Override
public void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) {
if(left != null) {
left.setBounds(0,0,imageWidth,imageHeight);
}
if(top != null) {
top.setBounds(0,0,imageWidth,imageHeight);
}
if(right != null) {
right.setBounds(0,0,imageWidth,imageHeight);
}
if(bottom != null) {
bottom.setBounds(0,0,imageWidth,imageHeight);
}
setCompoundDrawables(left,top,right,bottom);
}
}
<declare-styleable name="CustomDrawableTextView" >
<attr name="leftImage" format="reference" />
<attr name="topImage" format="reference" />
<attr name="rightImage" format="reference" />
<attr name="bottomImage" format="reference" />
<attr name="imageWidth" format="dimension" />
<attr name="imageHeight" format="dimension" />
</declare-styleable>
app:imageHeight="50dp" //图片高度
app:imageWidth="50dp" //图片宽度
app:leftImage="@drawable/ic_qq" //左部图片
app:topImage="@drawable/ic_qq" //顶部图片
app:rightImage="@drawable/ic_qq" //右部图片
app:bottomImage="@drawable/ic_qq" //底部图片
compile 'com.github.czy1121:roundbutton:1.0.0'
compile 'com.song:CustomDrawableTextView:1.0.0'
CustomDrawableTextView的更多相关文章
随机推荐
- 沃尔夫勒姆自动机时空图输出 C语言实现
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio.h> ...
- PHP 中的魔法常数
PHP中的魔法常数 PHP中有很多描述当前状态的魔法函数,可以很方便地获取运行时的局部环境 测试代码及结果如下 <?php namespace NS { function writeln($v= ...
- Aizu2249 Road Construction(dijkstra优化+思路 好题)
https://vjudge.net/problem/Aizu-2249 感觉这题和2017女生赛的Deleting Edge思路很像,都是先找最短路,然后替换边的. 但是这题用最朴素的dijkstr ...
- Google C++ 单元测试 GTest
from : http://www.cnblogs.com/jycboy/p/6057677.html 一.设置一个新的测试项目 在用google test写测试项目之前,需要先编译gtest到lib ...
- Java Web 清除缓存
res.setHeader("Cache-Control", "no-cache"); res.setHeader("Pragma", &q ...
- ABAP表生成Java实体Bean
项目中需要将HR模块中的表数据同步到Java系统中,向外围系统提供分发与查询服务,涉及到的表有两百多张,字段好几千上万个,如果手工一张张这些ABAP表在Java系统数据库中创建一遍的话,工作量将非常大 ...
- 使用sshfs将远程目录挂载到本地
使用sshfs将远程目录挂载到本地 转自:http://blog.sina.com.cn/s/blog_6561ca8c0102vc2u.html 在Linux下我们通常使用ssh命令来登录远程Lin ...
- centos7下使用rpm包安装clickhouse
clickhouse是由俄罗斯Yandex公司开发的列式存储数据库,于2016年开源,clickhouse的定位是快速的数据分析,对于处理海量数据的情况性能非常好,在网上也有很多测试的案例,在大数据的 ...
- java利用Tesseract 识别身份证号码
安装Tesseract http://blog.csdn.net/hiredme/article/details/50894814 http://blog.csdn.net/yoara/article ...
- Win10系统的DELL平板如何重装WIN10系统
首先参考"Win10系统的SurfacePro4如何重装系统-1 SurfacePro专用的PE"这篇文章,做一个WIN10平板专用的PE 然后开机按F2可以进入BIOS设置,如果 ...