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

The following examples show how to use android.view.View#requestLayout() . 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 check out the related API usage on the sidebar.
Example 1
Source File: GalleryView.java    From Nimbus with 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 2
Source File: ActivityShare.java    From XPrivacy with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: AndroidTreeView.java    From imsdk-android with 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 File: CollapseAnimator.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: ViewScaleHelper.java    From MultiItem with 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 6
Source File: ExpandableItem.java    From recyclerview-expandable with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: DownExpandAnimation.java    From MVPAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
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 8
Source File: ViewUtil.java    From appinventor-extensions with 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 9
Source File: AndroidTreeView.java    From javaide with GNU General Public License v3.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 10
Source File: QuestionWidget.java    From commcare-android with 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 11
Source File: MainActivity.java    From OpenWeatherPlus-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 兼容全面屏的状态栏高度
 */
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 12
Source File: FocusResizeScrollListener.java    From FocusResize with Apache License 2.0 5 votes vote down vote up
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 13
Source File: StaggeredGridView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
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 14
Source File: ChromeFullscreenManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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 15
Source File: Utils.java    From MapViewPager with 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 16
Source File: DemoActivity.java    From Phlux with 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 17
Source File: ViewUtils.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
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 18
Source File: ScreenUtil.java    From PicKing with 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 File: ViewUtils.java    From SUtil with 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 File: ProgressView.java    From SlidePager with 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();
}