Java Code Examples for android.view.ViewGroup#MarginLayoutParams

The following examples show how to use android.view.ViewGroup#MarginLayoutParams . 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: PViewSizeUtils.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
public static void setViewMargin(View view, int margin) {
    WeakReference<View> viewWeakReference = new WeakReference<>(view);
    if (viewWeakReference.get() != null) {
        if (viewWeakReference.get().getLayoutParams() != null &&
                (viewWeakReference.get().getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) {
            ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
            if (margin != -1) {
                params.leftMargin = margin;
                params.rightMargin = margin;
                params.topMargin = margin;
                params.bottomMargin = margin;
            }
            viewWeakReference.get().setLayoutParams(params);
        }
    }
}
 
Example 2
Source File: MarginLeftAttr.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(View view, int val)
{
    if(!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams))
    {
        return ;
    }
    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
    lp.leftMargin = val;
}
 
Example 3
Source File: Utils.java    From imsdk-android with MIT License 5 votes vote down vote up
static int getMarginEnd(View v) {
  if (v == null) {
    return 0;
  }
  ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
  return MarginLayoutParamsCompat.getMarginEnd(lp);
}
 
Example 4
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置标题栏MarginTop值为导航栏的高度
 * Sets title bar margin top.
 *
 * @param activity the activity
 * @param view     the view
 */
public static void setTitleBarMarginTop(Activity activity, @NonNull View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin + getStatusBarHeight(activity),
                layoutParams.rightMargin,
                layoutParams.bottomMargin);
    }
}
 
Example 5
Source File: ViewHelper.java    From tns-core-modules-widgets with Apache License 2.0 5 votes vote down vote up
public static int getMarginLeft(android.view.View view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params instanceof ViewGroup.MarginLayoutParams) {
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) params;
        return lp.leftMargin;
    }

    return 0;
}
 
Example 6
Source File: BarUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Add the top margin size equals status bar's height for view.
 *
 * @param view The view.
 */
public static void addMarginTopEqualStatusBarHeight(@NonNull View view) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
    view.setTag(TAG_OFFSET);
    Object haveSetOffset = view.getTag(KEY_OFFSET);
    if (haveSetOffset != null && (Boolean) haveSetOffset) return;
    ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
    layoutParams.setMargins(layoutParams.leftMargin,
            layoutParams.topMargin + getStatusBarHeight(),
            layoutParams.rightMargin,
            layoutParams.bottomMargin);
    view.setTag(KEY_OFFSET, true);
}
 
Example 7
Source File: Utils.java    From SmartTabLayout with Apache License 2.0 5 votes vote down vote up
static int getMarginEnd(View v) {
  if (v == null) {
    return 0;
  }
  ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
  return MarginLayoutParamsCompat.getMarginEnd(lp);
}
 
Example 8
Source File: StatusHelper.java    From MeiBaseModule with Apache License 2.0 5 votes vote down vote up
/**
 * set toolbar layout
 *
 * @param layoutResId
 * @param barHeight
 * @return
 */
public View setTitleLayout(@LayoutRes int layoutResId, int barHeight) {
    if (mTitleView != null) {
        return mTitleView;
    }
    setViewStubLayoutRes(R.id.base_action_bar_stub, layoutResId);
    mTitleView = inflateViewStub(R.id.base_action_bar_stub);
    if (mContentWrapView != null) {
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mContentWrapView
                .getLayoutParams();
        lp.topMargin = barHeight;
    }
    return mTitleView;
}
 
Example 9
Source File: ShapeBadgeItem.java    From BottomNavigation with Apache License 2.0 5 votes vote down vote up
/**
 * refresh's margin if set
 */
private void refreshMargin() {
    if (isWeakReferenceValid()) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) getTextView().get().getLayoutParams();
        layoutParams.bottomMargin = mEdgeMarginInPx;
        layoutParams.topMargin = mEdgeMarginInPx;
        layoutParams.rightMargin = mEdgeMarginInPx;
        layoutParams.leftMargin = mEdgeMarginInPx;
        getTextView().get().setLayoutParams(layoutParams);
    }
}
 
Example 10
Source File: SnackbarUtil.java    From weather with Apache License 2.0 5 votes vote down vote up
/**
 * Show the snackbar.
 */
public Snackbar show() {
  final View view = this.view;
  if (view == null) return null;
  if (messageColor != COLOR_DEFAULT) {
    SpannableString spannableString = new SpannableString(message);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(messageColor);
    spannableString.setSpan(
        colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
    );
    sReference = new WeakReference<>(Snackbar.make(view, spannableString, duration));
  } else {
    sReference = new WeakReference<>(Snackbar.make(view, message, duration));
  }
  final Snackbar snackbar = sReference.get();
  final View snackbarView = snackbar.getView();
  if (bgResource != -1) {
    snackbarView.setBackgroundResource(bgResource);
  } else if (bgColor != COLOR_DEFAULT) {
    snackbarView.setBackgroundColor(bgColor);
  }
  if (bottomMargin != 0) {
    ViewGroup.MarginLayoutParams params =
        (ViewGroup.MarginLayoutParams) snackbarView.getLayoutParams();
    params.bottomMargin = bottomMargin;
  }
  if (actionText.length() > 0 && actionListener != null) {
    if (actionTextColor != COLOR_DEFAULT) {
      snackbar.setActionTextColor(actionTextColor);
    }
    snackbar.setAction(actionText, actionListener);
  }
  snackbar.show();
  return snackbar;
}
 
Example 11
Source File: ExpandedScreen.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public void updatePaddings() {
	if (listView != null && (expandingEnabled || fullScreenLayoutEnabled)) {
		int actionBarHeight = obtainActionBarHeight(activity);
		int statusBarHeight = statusBar.getHeight();
		int bottomNavigationBarHeight = navigationBar.getBottom();
		int rightNavigationBarHeight = navigationBar.getRight();
		setNewPadding((View) listView.getParent(), 0, 0, rightNavigationBarHeight, 0);
		setNewPadding(listView, KEEP, statusBarHeight + actionBarHeight, KEEP, bottomNavigationBarHeight);
		if (actionModeView != null) {
			((ViewGroup.MarginLayoutParams) actionModeView.getLayoutParams()).rightMargin =
					rightNavigationBarHeight;
		}
		if (additionalViews != null) {
			for (LinkedHashMap.Entry<View, Boolean> additional : additionalViews.entrySet()) {
				additional.getKey().setPadding(0, statusBarHeight + (additional.getValue() ? actionBarHeight : 0),
						rightNavigationBarHeight, bottomNavigationBarHeight);
			}
		}
		if (drawerListView != null) {
			int paddingTop = C.API_LOLLIPOP && drawerOverToolbarEnabled && toolbarView != null
					? statusBarHeight : statusBarHeight + actionBarHeight;
			if (drawerHeader != null) {
				setNewPadding(drawerHeader, KEEP, paddingTop, KEEP, KEEP);
				setNewPadding(drawerListView, KEEP, 0, KEEP, bottomNavigationBarHeight);
			} else {
				setNewPadding(drawerListView, KEEP, paddingTop, KEEP, bottomNavigationBarHeight);
			}
		}
		if (contentForeground != null) {
			contentForeground.invalidateSelf();
		}
		if (statusBarContentForeground != null) {
			statusBarContentForeground.invalidateSelf();
		}
		if (statusBarDrawerForeground != null) {
			statusBarDrawerForeground.invalidateSelf();
		}
	}
}
 
Example 12
Source File: SpringLayout.java    From springlayout with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public LayoutParams(ViewGroup.MarginLayoutParams source) {
    super(source);
}
 
Example 13
Source File: MVHelper.java    From Tangram-Android with MIT License 4 votes vote down vote up
protected void renderLayout(BaseCell cell, View view) {
    if (cell.style != null) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();

        if (lp == null || !(lp instanceof VirtualLayoutManager.LayoutParams)) {
            if (lp == null) {
                lp = new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            } else {
                lp = new VirtualLayoutManager.LayoutParams(lp.width, lp.height);
            }
            view.setLayoutParams(lp);
        }
        if (lp instanceof VirtualLayoutManager.LayoutParams) {
            VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) lp;

            if (cell.style.height >= 0) {
                params.storeOriginHeight();
                params.height = cell.style.height;
            } else {
                params.restoreOriginHeight();
            }

            if (cell.style.width >= 0) {
                params.storeOriginWidth();
                params.width = cell.style.width;
            } else {
                params.restoreOriginWidth();
            }

            params.mAspectRatio = cell.style.aspectRatio;

            params.zIndex = cell.style.zIndex;
            if (params.zIndex == 0) {
                if (cell.parent != null && cell.parent.style != null) {
                    params.zIndex = cell.parent.style.zIndex;
                }
            }
            if (VERSION.SDK_INT >= 21) {
                view.setZ(params.zIndex);
            }
        } else {
            if (cell.style.height >= 0) {
                lp.height = cell.style.height;
            }

            if (cell.style.width >= 0) {
                lp.width = cell.style.width;
            }
        }


        if (lp instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) lp;
            layoutParams.topMargin = cell.style.margin[MARGIN_TOP_INDEX];
            layoutParams.leftMargin = cell.style.margin[MARGIN_LEFT_INDEX];
            layoutParams.bottomMargin = cell.style.margin[MARGIN_BOTTOM_INDEX];
            layoutParams.rightMargin = cell.style.margin[MARGIN_RIGHT_INDEX];
        }

        // reset translation animation before reused
        view.setTranslationX(0);
        view.setTranslationY(0);
    }
}
 
Example 14
Source File: MarginLayoutParamsCompatJellybeanMr1.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd) {
    lp.setMarginEnd(marginEnd);
}
 
Example 15
Source File: MarginLayoutParamsCompatJellybeanMr1.java    From guideshow with MIT License 4 votes vote down vote up
public static int getMarginEnd(ViewGroup.MarginLayoutParams lp) {
    return lp.getMarginEnd();
}
 
Example 16
Source File: GridLayoutManager.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public LayoutParams(ViewGroup.MarginLayoutParams source) {
    super(source);
}
 
Example 17
Source File: MarginLayoutParamsCompat.java    From guideshow with MIT License 4 votes vote down vote up
@Override
public void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd) {
    MarginLayoutParamsCompatJellybeanMr1.setMarginEnd(lp, marginEnd);
}
 
Example 18
Source File: FrameLayout.java    From Carbon with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public LayoutParams(ViewGroup.MarginLayoutParams source) {
    super(source);
    if (gravity == 0)
        gravity = GravityCompat.START | Gravity.TOP;
}
 
Example 19
Source File: LauncherActivity.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Modifies various views parameters and visibility based on the user preferences.
 */
private void applyPrefToViews() {
    // Workaround v21+ status bar transparency issue.
    // This is disabled if the status bar is hidden.
    if (Utils.atLeastLollipop()
            && (PreferenceHelper.getWindowBarMode().equals("none")
            || PreferenceHelper.getWindowBarMode().equals("nav"))) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        ViewGroup.MarginLayoutParams homeParams = (ViewGroup.MarginLayoutParams) slidingHome
                .getLayoutParams();
        homeParams.topMargin = ViewUtils.getStatusBarHeight();
    }

    slidingHome.post(new Runnable() {
        @Override public void run() {
            // Hide the favourites panel when there's nothing to show.
            if (pinnedAppsAdapter.isEmpty()) {
                pinnedAppsContainer.setTranslationY(pinnedAppsContainer.getMeasuredHeight());
                isFavouritesVisible = false;
            } else {
                isFavouritesVisible = true;
            }
        }
    });

    // Switch on wallpaper shade.
    if (PreferenceHelper.useWallpaperShade()) {
        // Tints the navigation bar with a semi-transparent shade.
        if (Utils.atLeastLollipop()) {
            getWindow().setNavigationBarColor(
                    getResources().getColor(R.color.navigationBarShade));
        }
        binding.wallpaperShade.setBackgroundResource(R.drawable.image_inner_shadow);
    }

    if ("transparent".equals(PreferenceHelper.getListBackground())) {
        appsListContainer.setBackgroundColor(
                Utils.getColorFromAttr(this, R.attr.backgroundColorAlt));
    } else if ("none".equals(PreferenceHelper.getListBackground())) {
        appsListContainer.setBackgroundColor(Color.TRANSPARENT);
    }
}
 
Example 20
Source File: MarginLayoutParamsCompat.java    From adt-leanback-support with Apache License 2.0 2 votes vote down vote up
/**
 * Get the relative ending margin that was set.
 *
 * <p>On platform versions supporting bidirectional text and layouts
 * this value will be resolved into the LayoutParams object's left or right
 * margin as appropriate when the associated View is attached to a window
 * or when the layout direction of that view changes.</p>
 *
 * @param lp LayoutParams to query
 * @return the margin along the ending edge in pixels
 */
public static int getMarginEnd(ViewGroup.MarginLayoutParams lp) {
    return IMPL.getMarginEnd(lp);
}