public final class

MarginLayoutParamsCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.view.MarginLayoutParamsCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.view.MarginLayoutParamsCompat android.support.v4.view.MarginLayoutParamsCompat

Overview

Helper for accessing API features in in a backwards compatible way.

Summary

Methods
public static intgetLayoutDirection(ViewGroup.MarginLayoutParams lp)

Returns the layout direction.

public static intgetMarginEnd(ViewGroup.MarginLayoutParams lp)

Get the relative ending margin that was set.

public static intgetMarginStart(ViewGroup.MarginLayoutParams lp)

Get the relative starting margin that was set.

public static booleanisMarginRelative(ViewGroup.MarginLayoutParams lp)

Check if margins are relative.

public static voidresolveLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection)

This will be called by View.

public static voidsetLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection)

Set the layout direction.

public static voidsetMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd)

Set the relative end margin.

public static voidsetMarginStart(ViewGroup.MarginLayoutParams lp, int marginStart)

Set the relative start margin.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static int getMarginStart(ViewGroup.MarginLayoutParams lp)

Deprecated: Use directly.

Get the relative starting margin that was set.

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.

Parameters:

lp: LayoutParams to query

Returns:

the margin along the starting edge in pixels

public static int getMarginEnd(ViewGroup.MarginLayoutParams lp)

Deprecated: Use directly.

Get the relative ending margin that was set.

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.

Parameters:

lp: LayoutParams to query

Returns:

the margin along the ending edge in pixels

public static void setMarginStart(ViewGroup.MarginLayoutParams lp, int marginStart)

Deprecated: Use directly.

Set the relative start margin.

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.

Parameters:

lp: LayoutParams to query
marginStart: the desired start margin in pixels

public static void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd)

Deprecated: Use directly.

Set the relative end margin.

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.

Parameters:

lp: LayoutParams to query
marginEnd: the desired end margin in pixels

public static boolean isMarginRelative(ViewGroup.MarginLayoutParams lp)

Deprecated: Use directly.

Check if margins are relative.

Returns:

true if either marginStart or marginEnd has been set.

public static int getLayoutDirection(ViewGroup.MarginLayoutParams lp)

Deprecated: Use directly.

Returns the layout direction. Can be either ViewCompat.LAYOUT_DIRECTION_LTR or ViewCompat.LAYOUT_DIRECTION_RTL.

Returns:

the layout direction.

public static void setLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection)

Deprecated: Use directly.

Set the layout direction.

Parameters:

lp: LayoutParameters for which to set the layout direction.
layoutDirection: the layout direction. Should be either ViewCompat.LAYOUT_DIRECTION_LTR or ViewCompat.LAYOUT_DIRECTION_RTL.

public static void resolveLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection)

Deprecated: Use directly.

This will be called by View. Left and Right margins may be overridden depending on layout direction.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package androidx.core.view;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

/**
 * Helper for accessing API features in
 * {@link ViewGroup.MarginLayoutParams MarginLayoutParams} in a backwards compatible
 * way.
 *
 * @deprecated Use {@link ViewGroup.MarginLayoutParams} directly.
 */
@Deprecated
public final class MarginLayoutParamsCompat {
    /**
     * Get the relative starting 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 starting edge in pixels
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#getMarginStart} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.getMarginStart()")
    @Deprecated
    public static int getMarginStart(@NonNull ViewGroup.MarginLayoutParams lp) {
        return lp.getMarginStart();
    }

    /**
     * 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
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#getMarginStart} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.getMarginEnd()")
    @Deprecated
    public static int getMarginEnd(@NonNull ViewGroup.MarginLayoutParams lp) {
        return lp.getMarginEnd();
    }

    /**
     * Set the relative start margin.
     *
     * <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
     * @param marginStart the desired start margin in pixels
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#setMarginStart} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.setMarginStart(marginStart)")
    @Deprecated
    public static void setMarginStart(@NonNull ViewGroup.MarginLayoutParams lp, int marginStart) {
        lp.setMarginStart(marginStart);
    }

    /**
     * Set the relative end margin.
     *
     * <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
     * @param marginEnd the desired end margin in pixels
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#setMarginEnd} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.setMarginEnd(marginEnd)")
    @Deprecated
    public static void setMarginEnd(@NonNull ViewGroup.MarginLayoutParams lp, int marginEnd) {
        lp.setMarginEnd(marginEnd);
    }

    /**
     * Check if margins are relative.
     *
     * @return true if either marginStart or marginEnd has been set.
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#isMarginRelative} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.isMarginRelative()")
    @Deprecated
    public static boolean isMarginRelative(@NonNull ViewGroup.MarginLayoutParams lp) {
        return lp.isMarginRelative();
    }

    /**
     * Returns the layout direction. Can be either {@link ViewCompat#LAYOUT_DIRECTION_LTR} or
     * {@link ViewCompat#LAYOUT_DIRECTION_RTL}.
     *
     * @return the layout direction.
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#getLayoutDirection} directly.
     */
    @Deprecated
    public static int getLayoutDirection(@NonNull ViewGroup.MarginLayoutParams lp) {
        int result;
        result = lp.getLayoutDirection();

        if ((result != View.LAYOUT_DIRECTION_LTR)
                && (result != View.LAYOUT_DIRECTION_RTL)) {
            // This can happen on older platform releases where the default (unset) layout direction
            // is -1
            result = View.LAYOUT_DIRECTION_LTR;
        }
        return result;
    }

    /**
     * Set the layout direction.
     *
     * @param lp LayoutParameters for which to set the layout direction.
     * @param layoutDirection the layout direction.
     *        Should be either {@link ViewCompat#LAYOUT_DIRECTION_LTR}
     *                     or {@link ViewCompat#LAYOUT_DIRECTION_RTL}.
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#setLayoutDirection} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.setLayoutDirection(layoutDirection)")
    @Deprecated
    public static void setLayoutDirection(@NonNull ViewGroup.MarginLayoutParams lp,
            int layoutDirection) {
        lp.setLayoutDirection(layoutDirection);
    }

    /**
     * This will be called by {@link View#requestLayout()}. Left and Right margins
     * may be overridden depending on layout direction.
     *
     * @deprecated Use {@link ViewGroup.MarginLayoutParams#resolveLayoutDirection} directly.
     */
    @androidx.annotation.ReplaceWith(expression = "lp.resolveLayoutDirection(layoutDirection)")
    @Deprecated
    public static void resolveLayoutDirection(@NonNull ViewGroup.MarginLayoutParams lp,
            int layoutDirection) {
        lp.resolveLayoutDirection(layoutDirection);
    }

    private MarginLayoutParamsCompat() {
    }

}