Android -- 自定义控件(ImageButton)

1. 效果图

  

 

2.  实现代码

  

package com.example.timetest;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ImageButton extends LinearLayout {

	private ImageView mImageView;

	private TextView mTextView;

	public ImageButton (
	               Context context , AttributeSet attrs ) {

		super ( context , attrs );

		mImageView = new ImageView ( context );
		mImageView.setImageResource ( R.drawable.add_tip );
		mImageView.setPadding ( 0 , 0 , 5 , 0 );
		mTextView = new TextView ( context );
		mTextView.setText ( "添加提醒" );
		setOrientation ( LinearLayout.HORIZONTAL );
		addView ( mImageView );
		addView ( mTextView );

	}

}

 3.  使用的图片

  

 

4.  使用自定义控件

 

 <com.example.timetest.ImageButton
        android:id="@+id/add"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:gravity="center" />   

 

      Ok  完成了

  

posted @ 2015-03-06 15:13  落寞回头不如华丽转身  阅读(210)  评论(0编辑  收藏  举报