Code example for BitmapDrawable

0
	public ProfileNameBannerContainer2(final Context context, final AttributeSet attrs, final int defStyle) { 
		super(context, attrs, defStyle); 
	} 
 
	public void setBanner(final Bitmap banner) { 
		setBackgroundDrawable(banner != null ? new BitmapDrawable(getResources(), banner) : null); 
	} 
 
	@Override 
	protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 
		final int parentWidth = MeasureSpec.getSize(widthMeasureSpec); 
		setMeasuredDimension(parentWidth, parentWidth / 2); 
		final ViewGroup.LayoutParams lp = getLayoutParams(); 
		lp.width = parentWidth; 
		lp.height = parentWidth / 2; 
		setLayoutParams(lp); 
		super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
	} 
}