I am building an application and there is a profile fragment which shows a profile background image and some other elements. Like the screenshot below:
My quest
this problem maybe caused by this commit
I fixed it programmatically with the way comment by @Bogdan Zurac.
mCollapseContentLy = findViewById(R.id.ly_collapse_content);
mCollapseContentLy.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int measuredHeight = mCollapseContentLy.getMeasuredHeight();
ViewGroup.LayoutParams lp = mCollapsingToolbarLayout.getLayoutParams();
layoutParams.height = measuredHeight;
mCollapsingToolbarLayout.setLayoutParams(lp);
mCollapseContentLy.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
create a new class extend CollapsingToolbarLayout
and override the onMeasure
method
package android.support.design.widget;
import android.content.Context;
import android.util.AttributeSet;
public class GodCollapsingToolbarLayout extends CollapsingToolbarLayout {
public GodCollapsingToolbarLayout(Context context) {
this(context, null);
}
public GodCollapsingToolbarLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public GodCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int mode = MeasureSpec.getMode(heightMeasureSpec);
final int topInset = mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0;
if (mode == MeasureSpec.UNSPECIFIED && topInset > 0) {
// fix the bottom empty padding
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
getMeasuredHeight() - topInset, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}