@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int childRight = right - left; int childBottom = bottom - top; int childLeft = 0; int childTop = 0; int y = (childBottom - mAvatarSize) / 2; childLeft += mSpacing; mAvatarDrawable.setBounds(childLeft, y, childLeft + mAvatarSize, y + mAvatarSize); childLeft += mAvatarSize + mSpacing; if (mButton != null) { mButton.layout(childRight - mButtonSize, childTop, childRight, childBottom); childRight -= mButtonSize; } if (mNameView.getVisibility() == View.VISIBLE) { if (mAddressView.getVisibility() == View.VISIBLE) { childTop = (childBottom - mNameView.getMeasuredHeight() - mAddressView.getMeasuredHeight()) / 2; mNameView.layout( childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight()); childTop += mNameView.getMeasuredHeight(); mAddressView.layout( childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight()); } else { childTop = (childBottom - mNameView.getMeasuredHeight()) / 2; mNameView.layout( childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight()); } } else if (mAddressView.getVisibility() == View.VISIBLE) { childTop = (childBottom - mAddressView.getMeasuredHeight()) / 2; mAddressView.layout( childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight()); } }
@Override public void draw(Canvas canvas) { super.draw(canvas); mAvatarDrawable.draw(canvas); }
public void setAvatarBitmap(Bitmap bm) { mAvatarDrawable.setImage(bm); invalidate(); }