private void setMaxWidth() {
int llWidth = binding.llTitle.getWidth();
// ivVipWidth = 50dp = layout_width+layout_marginStart
int ivVipWidth = dp2px(rootView.getContext(),50);
int maxWidth = llWidth - ivVipWidth;
binding.tvFirstTitle.setMaxWidth(maxWidth);
}
//onCreate中
binding.ivVip.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
binding.ivVip.getViewTreeObserver().removeGlobalOnLayoutListener(this);
setMaxWidth();
}
});
网友评论