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

    int heightSize = View.MeasureSpec.getSize(heightMeasureSpec);
    int heightMode = View.MeasureSpec.getMode(heightMeasureSpec);
    int tmpHeightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);

    int widthSize = View.MeasureSpec.getSize(widthMeasureSpec);
    int widthMode = View.MeasureSpec.getMode(widthMeasureSpec);
    int tmpWidthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);

    // fixed scrollview height problems
    if (heightMode == MeasureSpec.UNSPECIFIED
        && getParent() != null
        && (getParent() instanceof ScrollView)) {
      int baseHeight = 0;
      Context context = getContext();
      if (context instanceof Activity) {
        Activity act = (Activity) context;
        int measuredHeight = act.findViewById(android.R.id.content).getMeasuredHeight();
        baseHeight = measuredHeight;
      } else {
        baseHeight = getScreenHeight();
      }
      tmpHeightMeasureSpec = MeasureSpec.makeMeasureSpec(baseHeight, heightMode);
    }

    mPercentLayoutHelper.adjustChildren(tmpWidthMeasureSpec, tmpHeightMeasureSpec);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (mPercentLayoutHelper.handleMeasuredStateTooSmall()) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }
 @Override
 protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) {
   PercentLayoutHelper.fetchWidthAndHeight(this, a, widthAttr, heightAttr);
 }
 public LayoutParams(Context c, AttributeSet attrs) {
   super(c, attrs);
   mPercentLayoutInfo = PercentLayoutHelper.getPercentLayoutInfo(c, attrs);
 }
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   super.onLayout(changed, l, t, r, b);
   mPercentLayoutHelper.restoreOriginalParams();
 }