android.view.ViewGroup.MarginLayoutParams#setMargins ( )源码实例Demo

下面列出了android.view.ViewGroup.MarginLayoutParams#setMargins ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: relight   文件: ViewUtils.java
public static void setMargin(View v, Integer l, Integer t, Integer r, Integer b) {
    MarginLayoutParams p = getMarginInfo(v);
    if (null == p) {
        return;
    }
    if (l == null)
        l = p.leftMargin;
    if (t == null)
        t = p.topMargin;
    if (r == null)
        r = p.rightMargin;
    if (b == null)
        b = p.bottomMargin;
    p.setMargins(l, t, r, b);
    v.requestLayout();
}
 
源代码2 项目: GravityBox   文件: BatteryBarView.java
private void updatePosition() {
    MarginLayoutParams lp = null;
    if (mContainerType == ContainerType.STATUSBAR) {
        lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                mHeightPx);
        ((FrameLayout.LayoutParams)lp).gravity = mPosition == Position.TOP ? 
            Gravity.TOP : Gravity.BOTTOM;
    } else if (mContainerType == ContainerType.KEYGUARD) {
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                mHeightPx);
        if (mPosition == Position.TOP) {
            ((RelativeLayout.LayoutParams)lp).addRule(RelativeLayout.ALIGN_PARENT_TOP,
                    RelativeLayout.TRUE);
        } else {
            ((RelativeLayout.LayoutParams)lp).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
                    RelativeLayout.TRUE);
        }
    }

    if (lp != null) {
        lp.setMargins(0, mPosition == Position.TOP ? mMarginPx : 0,
                    0, mPosition == Position.BOTTOM ? mMarginPx : 0);
        setLayoutParams(lp);
    }
}
 
源代码3 项目: delion   文件: BookmarkPage.java
/**
 * Create a new instance of the bookmarks page.
 * @param activity The activity to get context and manage fragments.
 * @param tab The tab to load urls.
 */
public BookmarkPage(Activity activity, Tab tab) {
    mActivity = activity;
    mTab = tab;
    mTitle = activity.getString(R.string.bookmarks);
    mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources(),
            R.color.default_primary_color);
    mThemeColor = ApiCompatibilityUtils.getColor(
            activity.getResources(), R.color.default_primary_color);

    mManager = new BookmarkManager(mActivity, false);
    Resources res = mActivity.getResources();

    MarginLayoutParams layoutParams = new MarginLayoutParams(
            MarginLayoutParams.MATCH_PARENT, MarginLayoutParams.MATCH_PARENT);
    layoutParams.setMargins(0,
            res.getDimensionPixelSize(R.dimen.tab_strip_height)
            + res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow),
            0, 0);
    mManager.getView().setLayoutParams(layoutParams);
    mManager.setUrlChangeListener(this);
}
 
源代码4 项目: quickmark   文件: PiewController.java
public static void setLayout(View view, int x, int y) {
	MarginLayoutParams margin = new MarginLayoutParams(
			view.getLayoutParams());
	margin.setMargins(x, y, x + margin.width, y + margin.height);
	RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
			margin);
	view.setLayoutParams(layoutParams);
}
 
源代码5 项目: simple-keyboard   文件: ViewLayoutUtils.java
public static void placeViewAt(final View view, final int x, final int y, final int w,
        final int h) {
    final ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp instanceof MarginLayoutParams) {
        final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp;
        marginLayoutParams.width = w;
        marginLayoutParams.height = h;
        marginLayoutParams.setMargins(x, y, -50, 0);
    }
}
 
源代码6 项目: AOSP-Kayboard-7.1.2   文件: ViewLayoutUtils.java
public static void placeViewAt(final View view, final int x, final int y, final int w,
        final int h) {
    final ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp instanceof MarginLayoutParams) {
        final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp;
        marginLayoutParams.width = w;
        marginLayoutParams.height = h;
        marginLayoutParams.setMargins(x, y, 0, 0);
    }
}
 
源代码7 项目: GravityBox   文件: ProgressBarView.java
private void updatePosition() {
    if (mMode == Mode.OFF) return;

    MarginLayoutParams lp = null;
    if (mContainerType == ContainerType.STATUSBAR) {
        lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                mHeightPx);
        ((FrameLayout.LayoutParams)lp).gravity = mMode == Mode.TOP ? 
                Gravity.TOP : Gravity.BOTTOM;
    } else if (mContainerType == ContainerType.KEYGUARD) {
        lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                mHeightPx);
        if (mMode == Mode.TOP) {
            ((RelativeLayout.LayoutParams)lp).addRule(RelativeLayout.ALIGN_PARENT_TOP,
                    RelativeLayout.TRUE);
        } else {
            ((RelativeLayout.LayoutParams)lp).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
                    RelativeLayout.TRUE);
        }
    }

    if (lp != null) {
        lp.setMargins(0, mMode == Mode.TOP ? mEdgeMarginPx : 0,
                      0, mMode == Mode.BOTTOM ? mEdgeMarginPx : 0);
        setLayoutParams(lp);
    }
}
 
源代码8 项目: Indic-Keyboard   文件: ViewLayoutUtils.java
public static void placeViewAt(final View view, final int x, final int y, final int w,
        final int h) {
    final ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp instanceof MarginLayoutParams) {
        final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp;
        marginLayoutParams.width = w;
        marginLayoutParams.height = h;
        marginLayoutParams.setMargins(x, y, 0, 0);
    }
}
 
源代码9 项目: AndroidUtilCode   文件: BarUtils.java
/**
 * Subtract the top margin size equals status bar's height for view.
 *
 * @param view The view.
 */
public static void subtractMarginTopEqualStatusBarHeight(@NonNull View view) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
    Object haveSetOffset = view.getTag(KEY_OFFSET);
    if (haveSetOffset == null || !(Boolean) haveSetOffset) return;
    MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
    layoutParams.setMargins(layoutParams.leftMargin,
            layoutParams.topMargin - getStatusBarHeight(),
            layoutParams.rightMargin,
            layoutParams.bottomMargin);
    view.setTag(KEY_OFFSET, false);
}
 
源代码10 项目: AndroidChromium   文件: MarginResizer.java
private void updateMargins() {
    MarginLayoutParams layoutParams = (MarginLayoutParams) mView.getLayoutParams();
    if (mCurrentDisplayStyle == UiConfig.DISPLAY_STYLE_WIDE) {
        layoutParams.setMargins(mWideMarginSizePixels, layoutParams.topMargin,
                mWideMarginSizePixels, layoutParams.bottomMargin);
    } else {
        layoutParams.setMargins(mDefaultMarginSizePixels, layoutParams.topMargin,
                mDefaultMarginSizePixels, layoutParams.bottomMargin);
    }
}
 
源代码11 项目: StickyHeaders   文件: StickyHeaderPositioner.java
private void matchMarginsToPadding(MarginLayoutParams layoutParams) {
    @Px int leftMargin = orientation == LinearLayoutManager.VERTICAL ?
            recyclerView.getPaddingLeft() : 0;
    @Px int topMargin = orientation == LinearLayoutManager.VERTICAL ?
            0 : recyclerView.getPaddingTop();
    @Px int rightMargin = orientation == LinearLayoutManager.VERTICAL ?
            recyclerView.getPaddingRight() : 0;
    layoutParams.setMargins(leftMargin, topMargin, rightMargin, 0);
}
 
源代码12 项目: 365browser   文件: SearchEnginePreference.java
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mListView = (ListView) getView().findViewById(android.R.id.list);
    int marginTop = getActivity().getResources().getDimensionPixelSize(
            R.dimen.search_engine_list_margin_top);
    MarginLayoutParams layoutParams = (MarginLayoutParams) mListView.getLayoutParams();
    layoutParams.setMargins(0, marginTop, 0, 0);
    mListView.setLayoutParams(layoutParams);
    mListView.setAdapter(mSearchEngineAdapter);
    mListView.setDivider(null);
}
 
源代码13 项目: quickmark   文件: PiewController.java
public static void setLayoutX(View view, int x) {
	MarginLayoutParams margin = new MarginLayoutParams(
			view.getLayoutParams());
	margin.setMargins(x, margin.topMargin, x + margin.width,
			margin.bottomMargin);
	RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
			margin);
	view.setLayoutParams(layoutParams);
}
 
源代码14 项目: quickmark   文件: PiewController.java
public static void setLayoutY(View view, int y) {
	MarginLayoutParams margin = new MarginLayoutParams(
			view.getLayoutParams());
	margin.setMargins(margin.leftMargin, y, margin.rightMargin, y
			+ margin.height);
	RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
			margin);
	view.setLayoutParams(layoutParams);
}
 
源代码15 项目: PaymentKit-Droid   文件: ViewUtils.java
public static void setMarginTop(final View v, final int margin) {
	final MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
	lp.setMargins(lp.leftMargin, margin, lp.rightMargin, lp.bottomMargin);
	v.setLayoutParams(lp);
}
 
源代码16 项目: PaymentKit-Droid   文件: ViewUtils.java
public static void setMarginLeft(final View v, final int margin) {
	final MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
	lp.setMargins(margin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
	v.setLayoutParams(lp);
}
 
源代码17 项目: PaymentKit-Droid   文件: ViewUtils.java
public static void setMarginBottom(final View v, final int margin) {
	final MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
	lp.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, margin);
	v.setLayoutParams(lp);
}
 
源代码18 项目: talkback   文件: OverlayController.java
@VisibleForTesting
void showToolTip(int toolTipToShowViewId, Rect itemBounds, SwitchAccessMenuLayout menuLayout) {
  View toolTipToShow = menuOverlay.findViewById(toolTipToShowViewId);
  if (toolTipToShow == null) {
    return;
  }

  // We don't need to hide the previous tool tip if it is the same one we want to show now.
  // However, we still need to adjust the margins of the tool tip (below) because the horizontal
  // position of the item may have changed even if the vertical position hasn't.
  if (lastToolTipViewIdShown != toolTipToShowViewId) {
    menuOverlay.findViewById(lastToolTipViewIdShown).setVisibility(View.GONE);
    toolTipToShow.setVisibility(View.VISIBLE);
    lastToolTipViewIdShown = toolTipToShowViewId;
  }

  // The length of the tool tip is the longer dimension between its height and width. Since all
  // tool tips are just transposed versions of each other, the width of the tool tip up
  // represents the longest dimension for all tool tips.
  int toolTipLength = menuOverlay.findViewById(R.id.tooltip_up).getWidth();
  MarginLayoutParams toolTipMargins = (MarginLayoutParams) toolTipToShow.getLayoutParams();
  toolTipMargins.setMargins(0, 0, 0, 0);
  if ((toolTipToShowViewId == R.id.tooltip_up) || (toolTipToShowViewId == R.id.tooltip_down)) {
    Point screenSize = ScreenUtils.getRealScreenSize(getContext());
    boolean isItemNearLeftEdge = itemBounds.centerX() < (screenSize.x / 2);
    int distanceFromItemCenterToScreenEdge =
        isItemNearLeftEdge ? itemBounds.centerX() : (screenSize.x - itemBounds.centerX());
    int distanceFromToolTipCenterToScreenEdge =
        (toolTipLength / 2) + menuOverlay.findViewById(R.id.menu_layout).getLeft();
    if (distanceFromItemCenterToScreenEdge > minDistanceFromToolTipToScreenEdge) {
      // Place the center of the tooltip at the center of the item.
      toolTipMargins.leftMargin = itemBounds.centerX() - distanceFromToolTipCenterToScreenEdge;
    } else {
      // Place the center of the tooltip at the item edge furthest from the screen edge.
      int itemEdge = isItemNearLeftEdge ? itemBounds.right : itemBounds.left;
      toolTipMargins.leftMargin = itemEdge - distanceFromToolTipCenterToScreenEdge;
    }
  } else {
    MarginLayoutParams menuMargins =
        (MarginLayoutParams) menuOverlay.findViewById(R.id.menu_layout).getLayoutParams();
    toolTipMargins.topMargin = itemBounds.centerY() - (toolTipLength / 2) - menuMargins.topMargin;
  }
  toolTipToShow.setLayoutParams(toolTipMargins);

  // Set the tooltip and content so a border can be drawn around the menu.
  menuLayout.setToolTipView(toolTipToShow);
}
 
源代码19 项目: talkback   文件: OverlayController.java
@VisibleForTesting
void adjustGlobalMenuButtonPosition(
    @Nullable DisplayCutout displayCutout, List<Rect> cutoutRects) {
  LayoutParams globalMenuButtonParams = globalMenuButtonOverlay.getParams();
  if (displayCutout == null) {
    globalMenuButtonParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
  } else {
    Point screenSize = ScreenUtils.getRealScreenSize(getContext());
    View menuButton = globalMenuButtonOverlay.findViewById(R.id.global_menu_button);
    int menuButtonWidth = menuButton.getWidth();
    int leftOfCenteredMenuButton = (screenSize.x / 2) - (menuButtonWidth / 2);
    Rect centeredMenuButton =
        new Rect(
            leftOfCenteredMenuButton,
            0,
            leftOfCenteredMenuButton + menuButtonWidth,
            menuButton.getHeight());

    // Clear the margins.
    MarginLayoutParams menuButtonMarginParams = (MarginLayoutParams) menuButton.getLayoutParams();
    menuButtonMarginParams.setMargins(0, 0, 0, 0);

    // Find the cutout that intersects the centered menu button. If there's space to the right of
    // the cutout, move there. Otherwise if there's space to the left, move there. If neither side
    // has space, move just below the cutout.
    int safeInsetLeft = displayCutout.getSafeInsetLeft();
    int safeInsetRight = displayCutout.getSafeInsetRight();
    boolean cutoutIntersectsCenteredMenuButton = false;
    for (Rect cutoutRect : cutoutRects) {
      if (Rect.intersects(centeredMenuButton, cutoutRect)) {
        cutoutIntersectsCenteredMenuButton = true;
        if ((screenSize.x - safeInsetRight - cutoutRect.right) > menuButtonWidth) {
          globalMenuButtonParams.gravity = Gravity.TOP | Gravity.END;
          menuButtonMarginParams.rightMargin = screenSize.x - cutoutRect.right - menuButtonWidth;
        } else if ((cutoutRect.left - safeInsetLeft) > menuButtonWidth) {
          globalMenuButtonParams.gravity = Gravity.TOP | Gravity.START;
          menuButtonMarginParams.leftMargin = cutoutRect.left - menuButtonWidth;
        } else {
          globalMenuButtonParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
          menuButtonMarginParams.topMargin = displayCutout.getSafeInsetTop();
        }
      }
    }
    if (!cutoutIntersectsCenteredMenuButton) {
      globalMenuButtonParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
    }
  }
  globalMenuButtonOverlay.setParams(globalMenuButtonParams);
}
 
源代码20 项目: PaymentKit-Droid   文件: ViewUtils.java
public static void setMarginRight(final View v, final int margin) {
	final MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
	lp.setMargins(lp.leftMargin, lp.topMargin, margin, lp.bottomMargin);
	v.setLayoutParams(lp);
}