Java Code Examples for android.view.ViewGroup.MarginLayoutParams#setMargins()
The following examples show how to use
android.view.ViewGroup.MarginLayoutParams#setMargins() .
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: ViewUtils.java From relight with Apache License 2.0 | 6 votes |
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(); }
Example 2
Source File: BookmarkPage.java From delion with Apache License 2.0 | 6 votes |
/** * 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); }
Example 3
Source File: BatteryBarView.java From GravityBox with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: PiewController.java From quickmark with MIT License | 5 votes |
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); }
Example 5
Source File: PiewController.java From quickmark with MIT License | 5 votes |
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); }
Example 6
Source File: SearchEnginePreference.java From 365browser with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: StickyHeaderPositioner.java From StickyHeaders with Apache License 2.0 | 5 votes |
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); }
Example 8
Source File: MarginResizer.java From AndroidChromium with Apache License 2.0 | 5 votes |
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); } }
Example 9
Source File: BarUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * 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); }
Example 10
Source File: ViewLayoutUtils.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
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); } }
Example 11
Source File: ProgressBarView.java From GravityBox with Apache License 2.0 | 5 votes |
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); } }
Example 12
Source File: ViewLayoutUtils.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
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); } }
Example 13
Source File: ViewLayoutUtils.java From simple-keyboard with Apache License 2.0 | 5 votes |
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); } }
Example 14
Source File: PiewController.java From quickmark with MIT License | 5 votes |
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); }
Example 15
Source File: ViewUtils.java From PaymentKit-Droid with Apache License 2.0 | 4 votes |
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); }
Example 16
Source File: OverlayController.java From talkback with Apache License 2.0 | 4 votes |
@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); }
Example 17
Source File: OverlayController.java From talkback with Apache License 2.0 | 4 votes |
@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); }
Example 18
Source File: ViewUtils.java From PaymentKit-Droid with Apache License 2.0 | 4 votes |
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); }
Example 19
Source File: ViewUtils.java From PaymentKit-Droid with Apache License 2.0 | 4 votes |
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); }
Example 20
Source File: ViewUtils.java From PaymentKit-Droid with Apache License 2.0 | 4 votes |
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); }