Skip to content
This repository was archived by the owner on Oct 15, 2018. It is now read-only.

fixbug gethight==0 #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ public final void setWidth(int width) {

public final int getContentSize() {
switch (mScrollDirection) {
case HORIZONTAL:
return mInnerLayout.getWidth();
case VERTICAL:
default:
return mInnerLayout.getHeight();
case HORIZONTAL:
return getMeasureWidth(mInnerLayout);
case VERTICAL:
default:
return getMeasureHight(mInnerLayout);
}
}

Expand Down Expand Up @@ -390,4 +390,47 @@ private void setTextColor(ColorStateList color) {
}
}


/**
* ��ȡij���ؼ��Ŀ��� ���÷�������View.getMeasuredWidth(),View.getMeasuredHeight() ����ȡ����
*
* @param child
*/
public static void measureView(View child) {
ViewGroup.LayoutParams p = child.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width);
int lpHeight = p.height;
int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight,
MeasureSpec.EXACTLY);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED);
}
child.measure(childWidthSpec, childHeightSpec);
}

private int getMeasureHight(View child) {
int result = child.getHeight();
if (result == 0) {
measureView(child);
result = child.getMeasuredHeight();
}
return result;
}

private int getMeasureWidth(View child) {
int result = child.getWidth();
if (result == 0) {
measureView(child);
result = child.getMeasuredWidth();
}
return result;
}

}