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的更多相关文章
随机推荐
- HDU5511 : Minimum Cut-Cut
设$d[x]$表示端点位于$x$子树内部的非树边条数,那么有两种情况: $1.$割去的两条树边$(x,fa[x]),(y,fa[y])$中,$x$是$y$的祖先,那么此时需要割去的非树边数量为$d[x ...
- X-factor Chains [POJ3421] [素数]
Description 给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的.其中 1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi ...
- mysql error
一.could not find driver 我们这里以 PDO 为例, 问题: PDO 连接数据库找不到驱动程序. 解决方法:在 php.ini 里面讲 php_pdo_mysql 和 php_ ...
- 使用html5 Canvas绘制线条(直线、折线等)
使用html5 Canvas绘制直线所需的CanvasRenderingContext2D对象的主要属性和方法(有"()"者为方法)如下: 属性或方法 基本描述 strokeSty ...
- lettcode笔记--Valid Parentheses
20.Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...
- Aizu2249 Road Construction(dijkstra优化+思路 好题)
https://vjudge.net/problem/Aizu-2249 感觉这题和2017女生赛的Deleting Edge思路很像,都是先找最短路,然后替换边的. 但是这题用最朴素的dijkstr ...
- Dijskstra算法
#include <iostream> #include <cstdio> #include <queue> #include <vector> usi ...
- Kubernetes中资源配额管理
设置资源请求数量 创建Pod的时候,可以为每个容器指定资源消耗的限制.Pod的资源请求限制则是Pod中所有容器请求资源的总和. apiVersion: v1 kind: Pod metadata: n ...
- Android support 26.0.0-alpha1 产生的问题(zz)
针对以下两个错误 Java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/Animato ...
- strncpy, strncpy_s
Defined in header <string.h> (1) char *strncpy( char *dest, const char *src, size_t co ...