开源控件TextDrawable
2016-04-11 17:42
211 查看
简单描述
TextDrawable的用处是把文字转为drawable,然后使用imgeView设置该drawable。TextDrawable实际上是自定义Drawable.
效果
用法
eclipse为例,只需要在项目里加入自定义Drawable,即TextDrawable类,然后再Activity调用即可。TextDrawable可以从下面地址的项目里找到
GitHub地址:https://github.com/amulyakhare/TextDrawable
使用
Activitypackage com.example.learing; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.widget.ImageView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 正方形 ImageView mImageOne = (ImageView) findViewById(R.id.img1); TextDrawable d = TextDrawable.builder().buildRound("1", Color.RED); mImageOne.setImageDrawable(d); // 圆形 ImageView mImageTwo = (ImageView) findViewById(R.id.img2); TextDrawable r = TextDrawable.builder().buildRect("J", Color.GREEN); mImageTwo.setImageDrawable(r); // 圆角矩形 ImageView mImageThree = (ImageView) findViewById(R.id.img3); TextDrawable l = TextDrawable.builder().buildRoundRect("S6", Color.YELLOW, 30); mImageThree.setImageDrawable(l); } }
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="vertical" android:background="#333" > <ImageView android:id="@+id/img1" android:layout_width="100dp" android:layout_height="100dp" android:layout_margin="10dp" /> <ImageView android:id="@+id/img2" android:layout_width="100dp" android:layout_height="100dp" android:layout_margin="10dp" /> <ImageView android:id="@+id/img3" android:layout_width="100dp" android:layout_height="100dp" android:layout_margin="10dp" /> </LinearLayout>
转载于:http://www.jcodecraeer.com/a/opensource/2014/1122/2044.html
相关文章推荐
- Java的内存机制
- 记boost在gcc的一个库链接问题generic_category()
- hadoop 集群新增节点配置
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ExtractAbstractServiceHandler' is defined
- html表单元素
- ansible-playbook如何判断并中断执行
- c++迭代器Iterator详解
- c++指针详解
- STL与.Net泛型类的比较
- lintcode: Distinct Subsequences
- eclipse之web开发【servlet】
- 堆和栈的区别(转过无数次的文章)
- 慕课linux学习笔记(四)常用命令(1)
- Orcale用户管理
- flex学习进度3
- c++实验3-个人所得税计算器
- c++快速简易入门教程_006继承
- 个性化推荐系统方向简单介绍
- 如何计算UDP/TCP检验和checksum
- int *p[3]和int (*p)[3] 的区别,举例说明