android自定义控件.pdf,android自定义控件实例(linearlayout组合textview和imageview).pdf

android 自定义控件实例 (Linearlayout 组合 TextView 和

ImageView)

2013-12-18 11:25:22

转载自:

/lib/view/open1328836804515.

html

很多时候 android 常用的控件不能满足我们的需求,那么我

们就需要自定义一个控件了。今天做了一个自定义控件的实

例,来分享下。

首先定义一个 layout 实现按钮内部布局:

1 <?xml version="1.0" encoding="utf-8"?>

2

xmlns:android="/apk/res/andro

id"

3 android:layout_width="fill_parent"

4 android:layout_height="fill_parent"

5 android:orientation="horizontal" >

6

7

8 android:id="@+id/imageView1"

9 android:layout_width="wrap_content"

10 android:layout_height="wrap_content"

11 android:layout_gravity="center_vertical"

12 android:paddingBottom="5dip"

13 android:paddingLeft="40dip"

14 android:paddingTop="5dip"

15 android:src="@drawable/right_icon" />

16

17

18 android:id="@+id/textView1"

19 android:layout_width="wrap_content"

20 android:layout_height="wrap_content"

21 android:layout_gravity="center_vertical"

22 android:layout_marginLeft="8dip"

23 android:text=" 确定 "

24 android:textColor="#000000" />

25

26

接下来写一个类继承 LinearLayout ,导入刚刚的布局,并且

设置需要的方法,从而使的能在代码中控制这个自定义控件

内容的显示。

1 public class ImageBtn extends LinearLayout {

2

3 private ImageView imageView;

4 private TextView textView;

5

6 public ImageBtn(Context context) {

7 super(context);

8 // TODO Auto-generated constructor stub

9 }

10 public ImageBtn(Context context, AttributeSet

attrs) {

11 super(context, attrs);

12 // TODO Auto-gen

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值