Android中利用LinearLayout继承实现ImageButton
来源:互联网 发布:c多线程socket编程 编辑:程序博客网 时间:2024/04/28 02:25
原理:通过继承Linearlayout,摆放自己所需的imageview和textview,形成ImageButton
直接上源码:
- import android.widget.TextView;
- public class ImageButton1 extends LinearLayout
- {
- private ImageView mImage;
- private TextView mText;
- public ImageButton1(Context context, AttributeSet attrs)
- {
- super(context,attrs);
- mImage = new ImageView(context,attrs);
- mImage.setPadding(0,0,0,0);
- mText = new TextView(context,attrs);
- //mText.setGravity(android.view.Gravity.CENTER_HORIZONTAL);
- // mText.setGravity(android.view.Gravity.CENTER_VERTICAL);
- mText.setPadding(0,0,0,0);
- setClickable(true);
- setFocusable(true);
- setBackgroundResource(android.R.drawable.btn_default);
- setOrientation(LinearLayout.VERTICAL);
- addView(mImage);
- addView(mText);
- }
- }
调用自己编写的ImageButton1
- <com.test.b.ImageButton1
- android:id="@+id/imbtn01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/icon"
- android:text="MOAR"
- android:textColor="#ff000000"
- />
注意调用ImageButton1时,要用全名:com.test.b.ImageButton1
效果:button中上图下文字
- Android中利用LinearLayout继承实现ImageButton
- Android中利用LinearLayout继承实现ImageButton
- Android中利用LinearLayout继承实现ImageButton
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中ImageButton实现“按下”效果
- Android自定义控件---继承Linearlayout
- Android中利用LinearLayout动态添加UI控件
- 利用LinearLayout实现屏幕分割
- Android LinearLayout实现多行多列
- DataGrid-利用imagebutton实现更新操作
- DataGrid-利用imagebutton实现删除操作
- android中ImageButton的使用
- android中自定义标签ImageButton
- Android中ImageView和ImageButton
- int 0x80(寻根究底)---关于内核空间与用户空间切换
- android H264(1): openCore简介
- 2011-07-22日志
- 磁盘 IO 性能 调优 多线程 总结
- android (21)
- Android中利用LinearLayout继承实现ImageButton
- keil c51中启动代码详细说明
- APT(Advanced Packaging Tool)
- 网络拓扑结构5-9-1读取数据库并训练预测(实际数值)
- Java同步机制总结--synchronized
- javascript 比较逻辑运算符
- 在Viz 3.x中如何导入Viz 2.8的打包文件.eva
- Django之新建项目全过程
- 位运算 67大牛