Java Code Examples for android.view.View#requestLayout()

The following examples show how to use android.view.View#requestLayout() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: appinventor-extensions   File: ViewUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void setChildHeightForHorizontalLayout(View view, int height) {
  // In a horizontal layout, if a child's height is set to fill parent, we can simply set the
  // LayoutParams height to fill parent.
  Object layoutParams = view.getLayoutParams();
  if (layoutParams instanceof LinearLayout.LayoutParams) {
    LinearLayout.LayoutParams linearLayoutParams = (LinearLayout.LayoutParams) layoutParams;
    switch (height) {
      case Component.LENGTH_PREFERRED:
        linearLayoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
        break;
      case Component.LENGTH_FILL_PARENT:
        linearLayoutParams.height = LinearLayout.LayoutParams.FILL_PARENT;
        break;
      default:
        linearLayoutParams.height = calculatePixels(view, height);
        break;
    }
    view.requestLayout();
  } else {
    Log.e("ViewUtil", "The view does not have linear layout parameters");
  }
}
 
Example 2
Source Project: Nimbus   File: GalleryView.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 3
Source Project: imsdk-android   File: AndroidTreeView.java    License: MIT License 6 votes vote down vote up
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 4
Source Project: MultiItem   File: ViewScaleHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 关闭缩放
 */
public synchronized void stopScaleModel() {
    if (!isInScaleMode) {
        return;
    }
    isInScaleMode = false;
    restoreView(contentView);
    restoreView(horizontalView);
    for (View view : verticalViewList) {
        restoreView(view);
        view.requestLayout();
    }
    horizontalView.setScaleX(1f);
    horizontalView.setScaleY(1f);

}
 
Example 5
@UiThread
private void collapse(@NonNull final View view) {
    isOpened = false;
    final int initialHeight = view.getMeasuredHeight();

    final Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                view.setVisibility(View.GONE);
                isOpened = false;
            } else {
                view.getLayoutParams().height = initialHeight -
                    (int) (initialHeight * interpolatedTime);
                view.requestLayout();
            }
        }
    };
    animation.setDuration(duration);
    view.startAnimation(animation);
}
 
Example 6
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 7
Source Project: commcare-android   File: QuestionWidget.java    License: Apache License 2.0 6 votes vote down vote up
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 8
public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if(interpolatedTime == 1){
                v.setVisibility(View.GONE);
            }else{
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration(500);
    v.startAnimation(a);
}
 
Example 9
public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 10
private void blueStreakOfProgress(Integer current, Integer max) {
	// Set up the progress bar
	if (mProgressWidth == 0) {
		final View vShareProgressEmpty = (View) findViewById(R.id.vShareProgressEmpty);
		mProgressWidth = vShareProgressEmpty.getMeasuredWidth();
	}
	// Display stuff
	if (max == 0)
		max = 1;
	int width = (int) ((float) mProgressWidth) * current / max;

	View vShareProgressFull = (View) findViewById(R.id.vShareProgressFull);
	vShareProgressFull.getLayoutParams().width = width;
	vShareProgressFull.invalidate();
	vShareProgressFull.requestLayout();
}
 
Example 11
Source Project: MapViewPager   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setMargins(View view, int left, int top, int right, int bottom) {
    if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        params.setMargins(left, top, right, bottom);
        view.requestLayout();
    }
}
 
Example 12
private void applyMarginToFullChildViews(ViewGroup contentView, float margin) {
    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;
        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();

        if (layoutParams.height == LayoutParams.MATCH_PARENT
                && layoutParams.topMargin != (int) margin) {
            layoutParams.topMargin = (int) margin;
            child.requestLayout();
            TraceEvent.instant("FullscreenManager:child.requestLayout()");
        }
    }
}
 
Example 13
/**
 * 兼容全面屏的状态栏高度
 */
public void setMargins(View view, int l, int t, int r, int b) {
    if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        p.setMargins(l, t, r, b);
        view.requestLayout();
    }
}
 
Example 14
private void requestLayoutChildren() {
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View v = getChildAt(i);
        if (v != null) v.requestLayout();
    }
}
 
Example 15
private void calculateScrolledPosition(int totalItemCount, RecyclerView recyclerView) {
    for (int j = 0; j < totalItemCount - 1; j++) {
        View view = recyclerView.getChildAt(j);
        if (view != null) {
            if (!(recyclerView.getChildViewHolder(view) instanceof FocusResizeAdapter.FooterViewHolder)) {
                if (j == itemToResize) {
                    onItemBigResize(view, recyclerView);
                } else {
                    onItemSmallResize(view, recyclerView);
                }
                view.requestLayout();
            }
        }
    }
}
 
Example 16
public static void setSize(@NonNull View view, int width, int height) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    lp.height = height;
    lp.width = width;
    view.requestLayout();
}
 
Example 17
Source Project: Phlux   File: DemoActivity.java    License: MIT License 4 votes vote down vote up
private void setWeight(int id, float progress) {
    View before = findViewById(id);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) before.getLayoutParams();
    layoutParams.weight = progress;
    before.requestLayout();
}
 
Example 18
Source Project: PicKing   File: ScreenUtil.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 设置view margin
 *
 * @param v
 * @param l
 * @param t
 * @param r
 * @param b
 */
public static void setMargins(View v, int l, int t, int r, int b) {
    if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
        p.setMargins(l, t, r, b);
        v.requestLayout();
    }
}
 
Example 19
Source Project: SUtil   File: ViewUtils.java    License: Artistic License 2.0 3 votes vote down vote up
/**
 * 设置View的外边距(Margins)
 *
 * @param view   要设置外边距的View
 * @param left   左侧外边距
 * @param top    顶部外边距
 * @param right  右侧外边距
 * @param bottom 底部外边距
 */
public static void setMargins(View view, int left, int top, int right, int bottom) {
    if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        p.setMargins(left, top, right, bottom);
        view.requestLayout();       //请求重绘
    }
}
 
Example 20
Source Project: SlidePager   File: ProgressView.java    License: MIT License 2 votes vote down vote up
/**
 * Allows to set the {@link ViewProgressBinding#progressStreakLeft} or {@link ViewProgressBinding#progressStreakRight} height accordingly to the CircularBar dimension.
 *
 * @param streakHeight The streak we want to set the dimension to
 */
public void setStreakHeight(View streakHeight) {
    streakHeight.getLayoutParams().height = (int) mBinding.circularBar.getDiameter();
    streakHeight.requestLayout();
}