修复ToolbarActivity导致的内存泄漏问题
This commit is contained in:
@ -83,8 +83,6 @@ public abstract class ToolBarActivity extends BaseActivity implements ToolbarCon
|
||||
@Nullable
|
||||
private TextView mDownloadCountHint;
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -199,14 +197,17 @@ public abstract class ToolBarActivity extends BaseActivity implements ToolbarCon
|
||||
} else {
|
||||
final int[] diff = {0};
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) layoutParams;
|
||||
mOnGlobalLayoutListener = () -> {
|
||||
if (diff[0] != mActionMenuView.getWidth() - mBackContainer.getWidth()) {
|
||||
diff[0] = mActionMenuView.getWidth() - mBackContainer.getWidth();
|
||||
params.setMargins(diff[0], 0, 0, 0);
|
||||
mTitleContainer.setLayoutParams(params);
|
||||
mActionMenuView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
if (diff[0] != mActionMenuView.getWidth() - mBackContainer.getWidth()) {
|
||||
diff[0] = mActionMenuView.getWidth() - mBackContainer.getWidth();
|
||||
params.setMargins(diff[0], 0, 0, 0);
|
||||
mTitleContainer.setLayoutParams(params);
|
||||
}
|
||||
mActionMenuView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
};
|
||||
mActionMenuView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,11 +309,4 @@ public abstract class ToolBarActivity extends BaseActivity implements ToolbarCon
|
||||
mToolbarContainer.setVisibility(isHide ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mActionMenuView != null && mOnGlobalLayoutListener != null && !showToolbarAtLeft())
|
||||
mActionMenuView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user