重写onMeasure方法
protected voidonMeasure(int widthMeasureSpec, int heightMeasureSpec){
Drawable d =getDrawable();
if(d!=null){
// ceil notround - avoid thin vertical gaps along the left/right edges
int width =MeasureSpec.getSize(widthMeasureSpec);
int height= (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() /
(float) d.getIntrinsicWidth());
setMeasuredDimension(width, height);
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override