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的更多相关文章
随机推荐
- android Resources 类的使用
使用 R.<resource_type>.<resource_name> 获取的是资源的一个 id (int 类型), 但有时候我们需要获取资源本身,这时候我们可以通过 Res ...
- 查看过多占用cpu的是哪部分代码?
https://www.linuxidc.com/Linux/2016-04/130528.htm (1)top命令可查看是哪个项目占用的cpu内存较大,找到该项目对应的PID (2)top -H - ...
- 深入理解JVM(3)——垃圾收集策略详解
Java虚拟机的内存模型分为五部分:程序计数器.Java虚拟机栈.本地方法栈.堆.方法区. 程序计数器.Java虚拟机栈.本地方法栈都是线程私有的,也就是每个线程都拥有这三个区域,而且这三个区域会随着 ...
- 命令和python模式转换
安装完paython成功之后,就必须了解一下:命令模式和python交互模式 1.我们输入 cmd 之后进入的运行环境就是命令模式 2.在命令模式下输入 python,看到>>> ...
- Codeforces909C Python Indentation(动态规划)
http://codeforces.com/problemset/problem/909/C dp[i][j]表示第i行缩进j的方案数. 当第i-1行为f时,无论当前行是f或s都必须缩进,即dp[i] ...
- 基于spring boot 2.x的websocket示例
spring boot 2/spring 5自带了websocket,下面是最基本的示例(包括java服务端.java客户端以及js客户端) 一.pom依赖 <dependencies> ...
- 轻量级的Web框架——Nancy
最近想找一个简单的.Net下的轻量级Web框架,作为用户的本地的一个WebServer,实现同浏览器程序的一些简单交互,并调用本地服务,实现类似浏览器插件的功能.它有如下几点要求: 简单,能快速账务, ...
- python下的selenium和PhantomJS
一般我们使用python的第三方库requests及框架scrapy来爬取网上的资源,但是设计javascript渲染的页面却不能抓取,此时,我们使用web自动化测试化工具Selenium+无界面浏览 ...
- docker安装mongodb并备份
安装 官方镜像地址: https://hub.docker.com/_/mongo?tab=description 可以查看对应的dockerfile, 通过观察docker-entrypoint.s ...
- Hadoop的启动和停止说明
Hadoop的启动和停止说明 sbin/start-all.sh 启动所有的Hadoop守护进程.包括NameNode. Secondary NameNode.DataNode.ResourceM ...