Skip to content

Commit

Permalink
Fixed width measuring mode to work with wrap_content & match_parent
Browse files Browse the repository at this point in the history
  • Loading branch information
duncandee committed Apr 25, 2013
1 parent 874f022 commit ec3429b
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static interface PinnedSectionedHeaderAdapter {
private float mHeaderOffset;
private boolean mShouldPin = true;
private int mCurrentSection = 0;
private int mWidthMode;
private int mHeightMode;

public PinnedHeaderListView(Context context) {
super(context);
Expand Down Expand Up @@ -127,7 +129,8 @@ private View getSectionHeaderView(int section, View oldView) {

private void ensurePinnedHeaderLayout(View header) {
if (header.isLayoutRequested()) {
int widthSpec = MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY);
int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), mWidthMode);

int heightSpec;
ViewGroup.LayoutParams layoutParams = header.getLayoutParams();
if (layoutParams != null && layoutParams.height > 0) {
Expand All @@ -136,8 +139,7 @@ private void ensurePinnedHeaderLayout(View header) {
heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
header.measure(widthSpec, heightSpec);
int height = header.getMeasuredHeight();
header.layout(0, 0, getWidth(), height);
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
}
}

Expand All @@ -161,6 +163,14 @@ public void setOnScrollListener(OnScrollListener l) {
mOnScrollListener = l;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

mWidthMode = MeasureSpec.getMode(widthMeasureSpec);
mHeightMode = MeasureSpec.getMode(heightMeasureSpec);
}

public void setOnItemClickListener(PinnedHeaderListView.OnItemClickListener listener) {
super.setOnItemClickListener(listener);
}
Expand Down

0 comments on commit ec3429b

Please sign in to comment.