Java Code Examples for android.view.ViewGroup.MarginLayoutParams
The following are top voted examples for showing how to use
android.view.ViewGroup.MarginLayoutParams. These examples are extracted from open source projects.
You can vote up the examples you like and your votes will be used in our system to generate
more good examples.
Example 1
Project: chromium-for-android-56-debug-video File: SnackbarView.java View source code | 6 votes |
void adjustViewPosition() { mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect); // Only update if the visible frame has changed, otherwise there will be a layout loop. if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) { mPreviousVisibleRect.set(mCurrentVisibleRect); int keyboardHeight = mParent.getHeight() - mCurrentVisibleRect.bottom + mCurrentVisibleRect.top; MarginLayoutParams lp = getLayoutParams(); lp.bottomMargin = keyboardHeight; if (mIsTablet) { int margin = mParent.getResources() .getDimensionPixelSize(R.dimen.snackbar_margin_tablet); ApiCompatibilityUtils.setMarginStart(lp, margin); lp.bottomMargin += margin; int width = mParent.getResources() .getDimensionPixelSize(R.dimen.snackbar_width_tablet); lp.width = Math.min(width, mParent.getWidth() - 2 * margin); } mView.setLayoutParams(lp); } }
Example 2
Project: letv File: MyRandomSeeFragment.java View source code | 6 votes |
private void findView() { this.mOperationBarView = this.root.findViewById(2131362660); this.mFooterLayout = UIs.inflate(this.mActivity, R.layout.fragment_my_download_worldcup_bottom, null); this.mFootCloseBtn = (Button) this.mFooterLayout.findViewById(R.id.btn_close_worldcup); this.mNullScrollView = (ScrollView) this.root.findViewById(R.id.scrollview_tip); this.mNullTip = (LinearLayout) this.root.findViewById(R.id.linearlayout_tip_download); this.mTextOpenTip = (TextView) this.root.findViewById(R.id.textv_open_worldcup_tip); ((MarginLayoutParams) this.mTextOpenTip.getLayoutParams()).topMargin = UIs.zoomWidth(LiveType.PLAY_LIVE_OTHER); this.mTextOpenSubTip = (TextView) this.root.findViewById(R.id.textv_open_worldcup_tip_line2); ((MarginLayoutParams) this.mTextOpenSubTip.getLayoutParams()).topMargin = UIs.zoomWidth(9); this.mListView = (ListView) this.root.findViewById(2131361938); this.mStartAllBtn = (Button) this.mOperationBarView.findViewById(2131362659); this.mPauseAllBtn = (Button) this.mOperationBarView.findViewById(2131362658); this.mOpenWorldCupBtn = (Button) this.root.findViewById(R.id.btn_open_close); this.mStartAllBtn.setOnClickListener(this.onClick); this.mPauseAllBtn.setOnClickListener(this.onClick); this.mOpenWorldCupBtn.setOnClickListener(this.onClick); this.mFootCloseBtn.setOnClickListener(this.onClick); this.mDialog = new CustomLoadingDialog(this.mActivity); this.mDialog.setCanceledOnTouchOutside(false); this.rootWatchAlertLayout = (RelativeLayout) this.root.findViewById(R.id.road_watch_ball_alert_layout); ((TextView) this.rootWatchAlertLayout.findViewById(R.id.road_watch_ball_alert)).setText(LetvTools.getTextFromServer(DialogMsgConstantId.CONSTANT_70013, getActivity().getResources().getString(2131100080))); this.rootWatchAlertLayout.setOnClickListener(this.onClick); setText(); }
Example 3
Project: newIPlay File: FixedViewUtil.java View source code | 5 votes |
public static void setGridViewHeightBasedOnChildren(GridView listView,int col) { // 获取listview的adapter ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } // 固定列宽,有多少列 int totalHeight = 0; // i每次加4,相当于listAdapter.getCount()小于等于4时 循环一次,计算一次item的高度, // listAdapter.getCount()小于等于8时计算两次高度相加 for (int i = 0; i < listAdapter.getCount(); i += col) { // 获取listview的每一个item View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); // 获取item的高度和 totalHeight += listItem.getMeasuredHeight(); totalHeight += listView.getVerticalSpacing(); if (i==listAdapter.getCount()-1) { totalHeight += listView.getVerticalSpacing(); } } // 获取listview的布局参数 LayoutParams params = listView.getLayoutParams(); // 设置高度 params.height = totalHeight; // 设置margin ((MarginLayoutParams) params).setMargins(10, 10, 10, 10); // 设置参数 listView.setLayoutParams(params); }
Example 4
Project: simple-keyboard File: ViewLayoutUtils.java View source code | 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 5
Project: chromium-net-for-android File: ApiCompatibilityUtils.java View source code | 5 votes |
/** * @see android.view.ViewGroup.MarginLayoutParams#setMarginEnd(int) */ public static void setMarginEnd(MarginLayoutParams layoutParams, int end) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.setMarginEnd(end); } else { layoutParams.rightMargin = end; } }
Example 6
Project: chromium-net-for-android File: ApiCompatibilityUtils.java View source code | 5 votes |
/** * @see android.view.ViewGroup.MarginLayoutParams#getMarginStart() */ public static int getMarginStart(MarginLayoutParams layoutParams) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return layoutParams.getMarginStart(); } else { return layoutParams.leftMargin; } }
Example 7
Project: Virtualview-Android File: ContainerService.java View source code | 5 votes |
public View getContainer(String viewType, int containerType, boolean createParam) { IContainer container = null; ViewBase vb = mVM.getView(viewType); if (null == vb) { vb = mVM.getDefaultImage(); vb.setViewType(viewType); } if (vb.isContainer()) { container = (IContainer) vb.getNativeView(); } else { ContainerMrg cm = mContainerMrg.get(containerType); if (null != cm) { container = cm.getContainer(mAppContext); } else { Log.e(TAG, "getContainer type invalidate:" + containerType); } } if (null != container) { container.setVirtualView(vb); if (createParam) { Layout.Params p = vb.getComLayoutParams(); MarginLayoutParams marginLayoutParams = new MarginLayoutParams(p.mLayoutWidth, p.mLayoutHeight); marginLayoutParams.leftMargin = p.mLayoutMarginLeft; marginLayoutParams.topMargin = p.mLayoutMarginTop; marginLayoutParams.rightMargin = p.mLayoutMarginRight; marginLayoutParams.bottomMargin = p.mLayoutMarginBottom; ((View)container).setLayoutParams(marginLayoutParams); } container.attachViews(); } return (View)container; }
Example 8
Project: chromium-for-android-56-debug-video File: StripLayoutHelper.java View source code | 5 votes |
/** * Displays the tab menu below the anchor tab. * @param anchorTab The tab the menu will be anchored to */ private void showTabMenu(StripLayoutTab anchorTab) { // 1. Bring the anchor tab to the foreground. int tabIndex = TabModelUtils.getTabIndexById(mModel, anchorTab.getId()); TabModelUtils.setIndex(mModel, tabIndex); // 2. Anchor the popupMenu to the view associated with the tab View tabView = TabModelUtils.getCurrentTab(mModel).getView(); mTabMenu.setAnchorView(tabView); // 3. Set the vertical offset to align the tab menu with bottom of the tab strip int verticalOffset = -(tabView.getHeight() - (int) mContext.getResources().getDimension(R.dimen.tab_strip_height)) - ((MarginLayoutParams) tabView.getLayoutParams()).topMargin; mTabMenu.setVerticalOffset(verticalOffset); // 4. Set the horizontal offset to align the tab menu with the right side of the tab int horizontalOffset = Math.round((anchorTab.getDrawX() + anchorTab.getWidth()) * mContext.getResources().getDisplayMetrics().density) - mTabMenu.getWidth() - ((MarginLayoutParams) tabView.getLayoutParams()).leftMargin; // Cap the horizontal offset so that the tab menu doesn't get drawn off screen. horizontalOffset = Math.max(horizontalOffset, 0); mTabMenu.setHorizontalOffset(horizontalOffset); mTabMenu.show(); }
Example 9
Project: YCWeather File: ViewUtil.java View source code | 5 votes |
public static void setAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace) { int totalHeight = getAbsListViewHeight(absListView, lineNumber, verticalSpace); ViewGroup.LayoutParams params = absListView.getLayoutParams(); params.height = totalHeight; ((MarginLayoutParams) params).setMargins(0, 0, 0, 0); absListView.setLayoutParams(params); }
Example 10
Project: chromium-for-android-56-debug-video File: MarginResizer.java View source code | 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 11
Project: letv File: RecyclerView.java View source code | 5 votes |
public LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams lp) { if (lp instanceof LayoutParams) { return new LayoutParams((LayoutParams) lp); } if (lp instanceof MarginLayoutParams) { return new LayoutParams((MarginLayoutParams) lp); } return new LayoutParams(lp); }
Example 12
Project: AOSP-Kayboard-7.1.2 File: ViewLayoutUtils.java View source code | 5 votes |
public static MarginLayoutParams newLayoutParam(final ViewGroup placer, final int width, final int height) { if (placer instanceof FrameLayout) { return new FrameLayout.LayoutParams(width, height); } else if (placer instanceof RelativeLayout) { return new RelativeLayout.LayoutParams(width, height); } else if (placer == null) { throw new NullPointerException("placer is null"); } else { throw new IllegalArgumentException("placer is neither FrameLayout nor RelativeLayout: " + placer.getClass().getName()); } }
Example 13
Project: boohee_v5.6 File: TabLayout.java View source code | 5 votes |
private void updateTextAndIcon(@Nullable TextView textView, @Nullable ImageView iconView) { Drawable icon; CharSequence text; CharSequence contentDesc; boolean hasText; if (this.mTab != null) { icon = this.mTab.getIcon(); } else { icon = null; } if (this.mTab != null) { text = this.mTab.getText(); } else { text = null; } if (this.mTab != null) { contentDesc = this.mTab.getContentDescription(); } else { contentDesc = null; } if (iconView != null) { if (icon != null) { iconView.setImageDrawable(icon); iconView.setVisibility(0); setVisibility(0); } else { iconView.setVisibility(8); iconView.setImageDrawable(null); } iconView.setContentDescription(contentDesc); } if (TextUtils.isEmpty(text)) { hasText = false; } else { hasText = true; } if (textView != null) { if (hasText) { textView.setText(text); textView.setVisibility(0); setVisibility(0); } else { textView.setVisibility(8); textView.setText(null); } textView.setContentDescription(contentDesc); } if (iconView != null) { MarginLayoutParams lp = (MarginLayoutParams) iconView.getLayoutParams(); int bottomMargin = 0; if (hasText && iconView.getVisibility() == 0) { bottomMargin = TabLayout.this.dpToPx(8); } if (bottomMargin != lp.bottomMargin) { lp.bottomMargin = bottomMargin; iconView.requestLayout(); } } if (hasText || TextUtils.isEmpty(contentDesc)) { setOnLongClickListener(null); setLongClickable(false); return; } setOnLongClickListener(this); }
Example 14
Project: boohee_v5.6 File: DrawerLayoutCompatApi21.java View source code | 5 votes |
public static void applyMarginInsets(MarginLayoutParams lp, Object insets, int gravity) { WindowInsets wi = (WindowInsets) insets; if (gravity == 3) { wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom()); } else if (gravity == 5) { wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom()); } lp.leftMargin = wi.getSystemWindowInsetLeft(); lp.topMargin = wi.getSystemWindowInsetTop(); lp.rightMargin = wi.getSystemWindowInsetRight(); lp.bottomMargin = wi.getSystemWindowInsetBottom(); }
Example 15
Project: letv File: MarginLayoutParamsCompat.java View source code | 5 votes |
public static int getLayoutDirection(MarginLayoutParams lp) { int result = IMPL.getLayoutDirection(lp); if (result == 0 || result == 1) { return result; } return 0; }
Example 16
Project: GravityBox File: ProgressBarView.java View source code | 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 17
Project: ConstraintLayoutOverlap File: OverlappingDetector.java View source code | 5 votes |
private static int bottomWithMargin(@NonNull View view) { int safeBottom = view.getBottom(); if (view.getLayoutParams() instanceof MarginLayoutParams) { safeBottom += ((MarginLayoutParams) view.getLayoutParams()).bottomMargin; } return safeBottom; }
Example 18
Project: boohee_v5.6 File: CollapsingToolbarLayout.java View source code | 5 votes |
private static int getHeightWithMargins(@NonNull View view) { android.view.ViewGroup.LayoutParams lp = view.getLayoutParams(); if (!(lp instanceof MarginLayoutParams)) { return view.getHeight(); } MarginLayoutParams mlp = (MarginLayoutParams) lp; return (view.getHeight() + mlp.topMargin) + mlp.bottomMargin; }
Example 19
Project: boohee_v5.6 File: AnimCheckBox.java View source code | 5 votes |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); if (MeasureSpec.getMode(widthMeasureSpec) == Integer.MIN_VALUE && MeasureSpec.getMode (heightMeasureSpec) == Integer.MIN_VALUE) { MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); height = Math.min((dip(40) - params.leftMargin) - params.rightMargin, (dip(40) - params.bottomMargin) - params.topMargin); width = height; } int size = Math.min((width - getPaddingLeft()) - getPaddingRight(), (height - getPaddingBottom()) - getPaddingTop()); setMeasuredDimension(size, size); }
Example 20
Project: boohee_v5.6 File: RecyclerView.java View source code | 5 votes |
public LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams lp) { if (lp instanceof LayoutParams) { return new LayoutParams((LayoutParams) lp); } if (lp instanceof MarginLayoutParams) { return new LayoutParams((MarginLayoutParams) lp); } return new LayoutParams(lp); }
Example 21
Project: boohee_v5.6 File: Toolbar.java View source code | 5 votes |
private void measureChildConstrained(View child, int parentWidthSpec, int widthUsed, int parentHeightSpec, int heightUsed, int heightConstraint) { MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidthSpec = getChildMeasureSpec(parentWidthSpec, (((getPaddingLeft() + getPaddingRight()) + lp.leftMargin) + lp.rightMargin) + widthUsed, lp.width); int childHeightSpec = getChildMeasureSpec(parentHeightSpec, (((getPaddingTop() + getPaddingBottom()) + lp.topMargin) + lp.bottomMargin) + heightUsed, lp.height); int childHeightMode = MeasureSpec.getMode(childHeightSpec); if (childHeightMode != 1073741824 && heightConstraint >= 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(childHeightMode != 0 ? Math.min(MeasureSpec.getSize(childHeightSpec), heightConstraint) : heightConstraint, 1073741824); } child.measure(childWidthSpec, childHeightSpec); }
Example 22
Project: boohee_v5.6 File: Toolbar.java View source code | 5 votes |
private int measureChildCollapseMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed, int[] collapsingMargins) { MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int leftDiff = lp.leftMargin - collapsingMargins[0]; int rightDiff = lp.rightMargin - collapsingMargins[1]; int hMargins = Math.max(0, leftDiff) + Math.max(0, rightDiff); collapsingMargins[0] = Math.max(0, -leftDiff); collapsingMargins[1] = Math.max(0, -rightDiff); child.measure(getChildMeasureSpec(parentWidthMeasureSpec, ((getPaddingLeft() + getPaddingRight()) + hMargins) + widthUsed, lp.width), getChildMeasureSpec(parentHeightMeasureSpec, (((getPaddingTop() + getPaddingBottom()) + lp.topMargin) + lp.bottomMargin) + heightUsed, lp.height)); return child.getMeasuredWidth() + hMargins; }
Example 23
Project: boohee_v5.6 File: MarginLayoutParamsCompat.java View source code | 5 votes |
public static int getLayoutDirection(MarginLayoutParams lp) { int result = IMPL.getLayoutDirection(lp); if (result == 0 || result == 1) { return result; } return 0; }
Example 24
Project: boohee_v5.6 File: MarginLayoutParamsCompat.java View source code | 4 votes |
public int getMarginEnd(MarginLayoutParams lp) { return lp.rightMargin; }
Example 25
Project: boohee_v5.6 File: MarginLayoutParamsCompat.java View source code | 4 votes |
public void setLayoutDirection(MarginLayoutParams lp, int layoutDirection) { }
Example 26
Project: boohee_v5.6 File: DrawerLayout.java View source code | 4 votes |
public void applyMarginInsets(MarginLayoutParams lp, Object insets, int drawerGravity) { }
Example 27
Project: letv File: RecyclerView.java View source code | 4 votes |
public LayoutParams(MarginLayoutParams source) { super(source); }
Example 28
Project: letv File: GridLayoutManager.java View source code | 4 votes |
public LayoutParams(MarginLayoutParams source) { super(source); }
Example 29
Project: letv File: GridLayoutManager.java View source code | 4 votes |
public android.support.v7.widget.RecyclerView.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams lp) { if (lp instanceof MarginLayoutParams) { return new LayoutParams((MarginLayoutParams) lp); } return new LayoutParams(lp); }
Example 30
Project: letv File: StaggeredGridLayoutManager.java View source code | 4 votes |
public LayoutParams(MarginLayoutParams source) { super(source); }
Example 31
Project: letv File: StaggeredGridLayoutManager.java View source code | 4 votes |
public android.support.v7.widget.RecyclerView.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams lp) { if (lp instanceof MarginLayoutParams) { return new LayoutParams((MarginLayoutParams) lp); } return new LayoutParams(lp); }
Example 32
Project: boohee_v5.6 File: MarginLayoutParamsCompat.java View source code | 4 votes |
public void resolveLayoutDirection(MarginLayoutParams lp, int layoutDirection) { }
Example 33
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public int getMarginEnd(MarginLayoutParams lp) { return lp.rightMargin; }
Example 34
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public void setMarginStart(MarginLayoutParams lp, int marginStart) { lp.leftMargin = marginStart; }
Example 35
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public void setMarginEnd(MarginLayoutParams lp, int marginEnd) { lp.rightMargin = marginEnd; }
Example 36
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public boolean isMarginRelative(MarginLayoutParams lp) { return false; }
Example 37
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public int getLayoutDirection(MarginLayoutParams lp) { return 0; }
Example 38
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public void setLayoutDirection(MarginLayoutParams lp, int layoutDirection) { }
Example 39
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public void resolveLayoutDirection(MarginLayoutParams lp, int layoutDirection) { }
Example 40
Project: letv File: MarginLayoutParamsCompat.java View source code | 4 votes |
public int getMarginStart(MarginLayoutParams lp) { return MarginLayoutParamsCompatJellybeanMr1.getMarginStart(lp); }