首页 > 移动平台 > 详细

Android -- 自定义控件(ImageButton)

时间:2015-03-06 15:43:12      阅读:341      评论:0      收藏:0      [点我收藏+]

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  完成了

  

Android -- 自定义控件(ImageButton)

原文:http://www.cnblogs.com/SM-t/p/4318317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!