实现ImageButton里放置文字
2015-09-07 10:24
337 查看
1.自定义一个类 继承LinearLayout
2.建一个自定义defined.xml
3.在主类加载
4.效果
public ImageButton_define(Context context,AttributeSet attrs) { super(context, attrs); imageViewbutton = new ImageView(context, attrs); imageViewbutton.setPadding(0, 0, 0, 0); textView = new TextView(context, attrs); textView.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL); textView.setPadding(0, 0, 0, 0); setClickable(true); setFocusable(true); setBackgroundResource(android.R.drawable.btn_default); setOrientation(LinearLayout.VERTICAL); addView(textView); addView(imageViewbutton); }
2.建一个自定义defined.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <com.example.imagebutton.ImageButton_define android:id="@+id/define_iamgebutton" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#00000000" android:src="@null" android:text="图片文本" android:textColor="#cc0000" > </com.example.imagebutton.ImageButton_define> </LinearLayout>
3.在主类加载
setContentView(R.layout.difined);
4.效果
相关文章推荐
- windows下Qt环境搭建
- 页面渲染
- matlab读取指定路径下的图像
- [Java Concurrency in Practice]第十二章 并发程序的测试
- 滚动条到底部时左右滑出提示层jquery插件
- TQ2440 学习笔记—— 31、移植U-Boot【U-Boot 的启动过程第二阶段源码分析】
- HDU 2588 GCD(欧拉函数)
- 开发管理中常用的命令
- web_custom_request
- 网站自动提交至百度站长收录平台函数(适用任何框架代码)
- 国内VDI市场之乱象分析,第二篇:传输协议篇
- 8月全球搜索引擎市场:百度位居第四 份额大涨
- 收藏的js实现全国省份城市级联下拉菜单
- 敏捷思维和Scrum,哪个是第一位?
- MyEclipse2015 javaweb项目从svn检出后变成java项目,clean之后不能编译,解决办法是
- 使用assert() 查错
- bzoj1031 [JSOI2007]字符加密Cipher
- mysql 5.6 datetime default now()
- 问题:oracle decode;结果:oracle中的decode的使用
- Huffman编码 POJ 1521