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

The following are Jave code examples for showing how to use requestLayout() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: SunmiUI   File: ImageSharedTransitionActivity.java   Source Code and License Vote up 7 votes
private void performCircularReveal(View show) {
    show.setBackgroundColor(0xffff0000);
    ViewCompat.setTranslationY(show, 0);
    ViewCompat.setTranslationX(show, 0);
    show.getLayoutParams().height = 500;
    show.getLayoutParams().width = 1920;
    show.requestLayout();
    int centerX = (show.getLeft() + show.getRight()) / 2;
    int centerY = (show.getTop() + show.getBottom()) / 2;
    float finalRadius = (float) Math.hypot((double) centerX, (double) centerY);
    Animator mCircularReveal = ViewAnimationUtils.createCircularReveal(
            show, centerX, centerY, 0, finalRadius);
    mCircularReveal.setInterpolator(new AccelerateDecelerateInterpolator());
    mCircularReveal.setDuration(500);
    mCircularReveal.start();
}
 
Example 2
Project: boohee_v5.6   File: ExpandableLayout.java   Source Code and License Vote up 6 votes
private void expand(final View v) {
    v.measure(-1, -2);
    final int targetHeight = v.getMeasuredHeight();
    v.getLayoutParams().height = 0;
    v.setVisibility(0);
    this.animation = new Animation() {
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1.0f) {
                ExpandableLayout.this.isOpened = Boolean.valueOf(true);
            }
            v.getLayoutParams().height = interpolatedTime == 1.0f ? -2 : (int) (((float)
                    targetHeight) * interpolatedTime);
            v.requestLayout();
        }

        public boolean willChangeBounds() {
            return true;
        }
    };
    this.animation.setDuration((long) this.duration.intValue());
    v.startAnimation(this.animation);
}
 
Example 3
Project: XPrivacy   File: ActivityShare.java   Source Code and License Vote up 6 votes
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 4
Project: EasyEmoji   File: ViewUtil.java   Source Code and License Vote up 6 votes
public static boolean refreshHeight(final View view, final int aimHeight) {
    if (view.isInEditMode()) {
        return false;
    }

    if (view.getHeight() == aimHeight) {
        return false;
    }

    if (Math.abs(view.getHeight() - aimHeight) ==
            StatusBarHeightUtil.getStatusBarHeight(view.getContext())) {
        return false;
    }

    final int validPanelHeight = KeyboardManagerImpl.getValidPanelHeight(view.getContext());
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    if (layoutParams == null) {
        layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                validPanelHeight);
        view.setLayoutParams(layoutParams);
    } else {
        layoutParams.height = validPanelHeight;
        view.requestLayout();
    }

    return true;
}
 
Example 5
Project: Zoomable   File: ZoomableViewPagerAdapter.java   Source Code and License Vote up 6 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.zoomable_view_pager_item, null);
    ZoomableDraweeView zoomableDraweeView = (ZoomableDraweeView) view.findViewById(R.id.zoomable_image);
    //允许缩放时切换
    zoomableDraweeView.setAllowTouchInterceptionWhileZoomed(true);
    //长按
    zoomableDraweeView.setIsLongpressEnabled(false);
    //双击击放大或缩小
    zoomableDraweeView.setTapListener(new DoubleTapGestureListener(zoomableDraweeView));

    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setUri(mPaths.get(position))
            .build();
    //加载图片
    zoomableDraweeView.setController(draweeController);
    container.addView(view);
    view.requestLayout();
    return view;
}
 
Example 6
Project: appinventor-extensions   File: ViewUtil.java   Source Code and License Vote up 6 votes
public static void setChildHeightForTableLayout(View view, int height) {
  Object layoutParams = view.getLayoutParams();
  if (layoutParams instanceof TableRow.LayoutParams) {
    TableRow.LayoutParams tableLayoutParams = (TableRow.LayoutParams) layoutParams;
    switch (height) {
      case Component.LENGTH_PREFERRED:
        tableLayoutParams.height = TableRow.LayoutParams.WRAP_CONTENT;
        break;
      case Component.LENGTH_FILL_PARENT:
        tableLayoutParams.height = TableRow.LayoutParams.FILL_PARENT;
        break;
      default:
        tableLayoutParams.height = calculatePixels(view, height);
        break;
    }
    view.requestLayout();
  } else {
    Log.e("ViewUtil", "The view does not have table layout parameters");
  }
}
 
Example 7
Project: appinventor-extensions   File: ViewUtil.java   Source Code and License Vote up 6 votes
public static void setChildWidthForVerticalLayout(View view, int width) {
    // In a vertical layout, if a child's width is set to fill parent, we can simply set the
    // LayoutParams width to fill parent.
    Object layoutParams = view.getLayoutParams();
    if (layoutParams instanceof LinearLayout.LayoutParams) {
      LinearLayout.LayoutParams linearLayoutParams = (LinearLayout.LayoutParams) layoutParams;
      switch (width) {
        case Component.LENGTH_PREFERRED:
          linearLayoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
          break;
        case Component.LENGTH_FILL_PARENT:
          linearLayoutParams.width = LinearLayout.LayoutParams.FILL_PARENT;
          break;
        default:
          linearLayoutParams.width = calculatePixels(view, width);
          break;
      }
//      System.err.println("ViewUtil: setChildWidthForVerticalLayout: view = " + view + " width = " + width);
      view.requestLayout();
    } else {
      Log.e("ViewUtil", "The view does not have linear layout parameters");
    }
  }
 
Example 8
Project: Lunary-Ethereum-Wallet   File: CollapseAnimator.java   Source Code and License Vote up 6 votes
public static void expand(final View v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

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

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 9
Project: appinventor-extensions   File: ViewUtil.java   Source Code and License Vote up 6 votes
public static void setChildWidthForHorizontalLayout(View view, int width) {
  // In a horizontal layout, if a child's width is set to fill parent, we must set the
  // LayoutParams width to 0 and the weight to 1. For other widths, we set the weight to 0
  Object layoutParams = view.getLayoutParams();
  if (layoutParams instanceof LinearLayout.LayoutParams) {
    LinearLayout.LayoutParams linearLayoutParams = (LinearLayout.LayoutParams) layoutParams;
    switch (width) {
      case Component.LENGTH_PREFERRED:
        linearLayoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
        linearLayoutParams.weight = 0;
        break;
      case Component.LENGTH_FILL_PARENT:
        linearLayoutParams.width = 0;
        linearLayoutParams.weight = 1;
        break;
      default:
        linearLayoutParams.width = calculatePixels(view, width);
        linearLayoutParams.weight = 0;
        break;
    }
    view.requestLayout();
  } else {
    Log.e("ViewUtil", "The view does not have linear layout parameters");
  }
}
 
Example 10
Project: GravityBox   File: BaseTile.java   Source Code and License Vote up 5 votes
@Override
public void onRecreateLabel(View tileView) {
    if (mScalingFactor != 1f) {
        updateLabelLayout(tileView);
        tileView.requestLayout();
    }
}
 
Example 11
Project: GitHub   File: DensityUtil.java   Source Code and License Vote up 5 votes
/**
 * 设置某个View的margin
 *
 * @param view   需要设置的view
 * @param isDp   需要设置的数值是否为DP
 * @param left   左边距
 * @param right  右边距
 * @param top    上边距
 * @param bottom 下边距
 * @return
 */
public static ViewGroup.LayoutParams setViewMargin(View view, boolean isDp, int left, int right, int top, int bottom) {
    if (view == null) {
        return null;
    }

    int leftPx = left;
    int rightPx = right;
    int topPx = top;
    int bottomPx = bottom;
    ViewGroup.LayoutParams params = view.getLayoutParams();
    ViewGroup.MarginLayoutParams marginParams = null;
    //获取view的margin设置参数
    if (params instanceof ViewGroup.MarginLayoutParams) {
        marginParams = (ViewGroup.MarginLayoutParams) params;
    } else {
        //不存在时创建一个新的参数
        marginParams = new ViewGroup.MarginLayoutParams(params);
    }

    //根据DP与PX转换计算值
    if (isDp) {
        leftPx = dip2px(left);
        rightPx = dip2px(right);
        topPx = dip2px(top);
        bottomPx = dip2px(bottom);
    }
    //设置margin
    marginParams.setMargins(leftPx, topPx, rightPx, bottomPx);
    view.setLayoutParams(marginParams);
    view.requestLayout();
    return marginParams;
}
 
Example 12
Project: MyDemo   File: DensityUtil.java   Source Code and License Vote up 5 votes
/**
 * 设置某个View的margin
 *
 * @param view   需要设置的view
 * @param isDp   需要设置的数值是否为DP
 * @param left   左边距
 * @param right  右边距
 * @param top    上边距
 * @param bottom 下边距
 * @return
 */
public static ViewGroup.LayoutParams setViewMargin(View view, boolean isDp, int left, int right, int top, int bottom) {
    if (view == null) {
        return null;
    }

    int leftPx = left;
    int rightPx = right;
    int topPx = top;
    int bottomPx = bottom;
    ViewGroup.LayoutParams params = view.getLayoutParams();
    ViewGroup.MarginLayoutParams marginParams = null;
    //获取view的margin设置参数
    if (params instanceof ViewGroup.MarginLayoutParams) {
        marginParams = (ViewGroup.MarginLayoutParams) params;
    } else {
        //不存在时创建一个新的参数
        marginParams = new ViewGroup.MarginLayoutParams(params);
    }

    //根据DP与PX转换计算值
    if (isDp) {
        leftPx = dip2px(left);
        rightPx = dip2px(right);
        topPx = dip2px(top);
        bottomPx = dip2px(bottom);
    }
    //设置margin
    marginParams.setMargins(leftPx, topPx, rightPx, bottomPx);
    view.setLayoutParams(marginParams);
    view.requestLayout();
    return marginParams;
}
 
Example 13
Project: ucar-weex-core   File: LayoutParamsProperty.java   Source Code and License Vote up 5 votes
@Override
public void set(View object, Integer value) {
  LayoutParams layoutParams;
  if (object != null && (layoutParams = object.getLayoutParams()) != null) {
    setProperty(layoutParams, value);
    if (object instanceof IRenderResult) {
      WXComponent component = ((IRenderResult) object).getComponent();
      if (component != null) {
          component.notifyNativeSizeChanged(layoutParams.width, layoutParams.height);
      }
    }
    object.requestLayout();
  }
}
 
Example 14
Project: TIIEHenry-Android-SDK   File: TabLayout.java   Source Code and License Vote up 5 votes
private void updateTabViewsLayoutParams() {
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
  View child = mTabStrip.getChildAt(i);
  updateTabViewLayoutParams((LinearLayout.LayoutParams) child.getLayoutParams());
  child.requestLayout();
}
 }
 
Example 15
Project: SimpleUILauncher   File: LauncherAccessibilityDelegate.java   Source Code and License Vote up 5 votes
@Thunk void performResizeAction(int action, View host, LauncherAppWidgetInfo info) {
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) host.getLayoutParams();
    CellLayout layout = (CellLayout) host.getParent().getParent();
    layout.markCellsAsUnoccupiedForView(host);

    if (action == R.string.action_increase_width) {
        if (((host.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)
                && layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY))
                || !layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY)) {
            lp.cellX --;
            info.cellX --;
        }
        lp.cellHSpan ++;
        info.spanX ++;
    } else if (action == R.string.action_decrease_width) {
        lp.cellHSpan --;
        info.spanX --;
    } else if (action == R.string.action_increase_height) {
        if (!layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1)) {
            lp.cellY --;
            info.cellY --;
        }
        lp.cellVSpan ++;
        info.spanY ++;
    } else if (action == R.string.action_decrease_height) {
        lp.cellVSpan --;
        info.spanY --;
    }

    layout.markCellsAsOccupiedForView(host);
    Rect sizeRange = new Rect();
    AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, sizeRange);
    ((LauncherAppWidgetHostView) host).updateAppWidgetSize(null,
            sizeRange.left, sizeRange.top, sizeRange.right, sizeRange.bottom);
    host.requestLayout();
    LauncherModel.updateItemInDatabase(mLauncher, info);
    announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY));
}
 
Example 16
Project: TableView   File: TableViewUtils.java   Source Code and License Vote up 5 votes
/**
 * Helps to force width value before calling requestLayout by the system.
 */
public static void setWidth(View p_jView, int p_nWidth) {
    // Change width value from params
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) p_jView.getLayoutParams();
    params.width = p_nWidth;
    p_jView.setLayoutParams(params);

    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(p_nWidth, View.MeasureSpec.EXACTLY);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(p_jView.getMeasuredHeight(),
            View.MeasureSpec.EXACTLY);
    p_jView.measure(widthMeasureSpec, heightMeasureSpec);

    p_jView.requestLayout();
}
 
Example 17
Project: Nimbus   File: GalleryView.java   Source Code and License Vote up 5 votes
public  void expand(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? LayoutParams.WRAP_CONTENT
                    : (int)(targetHeight * interpolatedTime);
            v.requestLayout();
        }

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

    // 1dp/ms
    a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 18
Project: chromium-for-android-56-debug-video   File: ChromeFullscreenManager.java   Source Code and License Vote up 5 votes
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 19
Project: FancyTab   File: FancyTabLayout.java   Source Code and License Vote up 5 votes
void setFloatingTop() {

        int targetMargin = getResources().getDimensionPixelOffset(R.dimen.fancy_tab_margin_top);

        int margin = (int) (currentFloatMargin + ((targetMargin - currentFloatMargin) * appBarOffset));

        View tabs = (View) tabsContainer.getParent();
        CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) tabs.getLayoutParams();
        layoutParams.topMargin = margin;
        tabs.requestLayout();
    }
 
Example 20
Project: ShangHanLun   File: ATableView.java   Source Code and License Vote up 4 votes
@Override
protected void onAttachedToWindow() {
    mAdapter = new ATableViewAdapter(this);

    // TODO we should handle the case last row is
    // ListView.LayoutParams.WRAP_CONTENT, to get its height.
    // setup footer for plain tables to complete its height with empty rows.
    // ATTENSION: below has a bug which cause listview dead for no move
    // except be killed.
    // so I commented it.
    // setupFooterView(mAdapter.getLastRowHeight());

    if (needPinnedHeader()) {
        // TO DO: here can remove to PinnedView class.
        View HeaderView = LayoutInflater.from(getContext()).inflate(
                R.layout.pinnedheader, this, false);
        Resources res = getResources();
        Rect padding = new Rect();
        padding.left = (int) res
                .getDimension(R.dimen.atv_plain_section_header_padding_left);
        padding.right = (int) res
                .getDimension(R.dimen.atv_plain_section_header_padding_right);

        // set background for plain style.
        // HeaderView
        // .setBackgroundResource(R.drawable.plain_header_background);
        HeaderView.setBackgroundColor(Color.argb(178, 204, 204, 204));
        TextView label = (TextView) HeaderView.findViewById(R.id.textLabel);
        label.setTextColor(Color.BLUE);
        HeaderView.setPadding(padding.left, padding.top, padding.right,
                padding.bottom);
        ListView.LayoutParams params = new ListView.LayoutParams(
                ListView.LayoutParams.MATCH_PARENT,
                mAdapter.getHeaderFooterRowHeight(0, false));
        HeaderView.setLayoutParams(params);
        HeaderView.requestLayout();

        setHeaderView(HeaderView);
    }
    // setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setAdapter(mAdapter);
    setOnScrollListener(mAdapter);
    setOnItemClickListener(new ATableViewCellClickListener(this));
    super.onAttachedToWindow();
}