public final class

ViewGroupCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.view.ViewGroupCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.9.0-alpha04'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.9.0-alpha04

Artifact androidx.core:core:1.9.0-alpha04 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.ViewGroupCompat android.support.v4.view.ViewGroupCompat

Overview

Helper for accessing features in ViewGroup.

Summary

Fields
public static final intLAYOUT_MODE_CLIP_BOUNDS

This constant is a layoutMode.

public static final intLAYOUT_MODE_OPTICAL_BOUNDS

This constant is a layoutMode.

Methods
public static intgetLayoutMode(ViewGroup group)

Returns the basis of alignment during layout operations on this ViewGroup: either ViewGroupCompat.LAYOUT_MODE_CLIP_BOUNDS or ViewGroupCompat.LAYOUT_MODE_OPTICAL_BOUNDS.

public static intgetNestedScrollAxes(ViewGroup group)

Return the current axes of nested scrolling for this ViewGroup.

public static booleanisTransitionGroup(ViewGroup group)

Returns true if this ViewGroup should be considered as a single entity for removal when executing an Activity transition.

public static booleanonRequestSendAccessibilityEvent(ViewGroup group, View child, AccessibilityEvent event)

Called when a child has requested sending an and gives an opportunity to its parent to augment the event.

public static voidsetLayoutMode(ViewGroup group, int mode)

Sets the basis of alignment during the layout of this ViewGroup.

public static voidsetMotionEventSplittingEnabled(ViewGroup group, boolean split)

Enable or disable the splitting of MotionEvents to multiple children during touch event dispatch.

public static voidsetTransitionGroup(ViewGroup group, boolean isTransitionGroup)

Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions.

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

Fields

public static final int LAYOUT_MODE_CLIP_BOUNDS

This constant is a layoutMode. Clip bounds are the raw values of left, top, right and bottom.

public static final int LAYOUT_MODE_OPTICAL_BOUNDS

This constant is a layoutMode. Optical bounds describe where a widget appears to be. They sit inside the clip bounds which need to cover a larger area to allow other effects, such as shadows and glows, to be drawn.

Methods

public static boolean onRequestSendAccessibilityEvent(ViewGroup group, View child, AccessibilityEvent event)

Deprecated: Use ViewGroup directly.

Called when a child has requested sending an and gives an opportunity to its parent to augment the event.

If an AccessibilityDelegateCompat has been specified via calling ViewCompat.setAccessibilityDelegate(View, AccessibilityDelegateCompat) its AccessibilityDelegateCompat.onRequestSendAccessibilityEvent(ViewGroup, View, AccessibilityEvent) is responsible for handling this call.

Parameters:

group: The group whose method to invoke.
child: The child which requests sending the event.
event: The event to be sent.

Returns:

True if the event should be sent.

public static void setMotionEventSplittingEnabled(ViewGroup group, boolean split)

Deprecated: Use ViewGroup directly.

Enable or disable the splitting of MotionEvents to multiple children during touch event dispatch. This behavior is enabled by default for applications that target an SDK version of 11 (Honeycomb) or newer. On earlier platform versions this feature was not supported and this method is a no-op.

When this option is enabled MotionEvents may be split and dispatched to different child views depending on where each pointer initially went down. This allows for user interactions such as scrolling two panes of content independently, chording of buttons, and performing independent gestures on different pieces of content.

Parameters:

group: ViewGroup to modify
split: true to allow MotionEvents to be split and dispatched to multiple child views. false to only allow one child view to be the target of any MotionEvent received by this ViewGroup.

public static int getLayoutMode(ViewGroup group)

Returns the basis of alignment during layout operations on this ViewGroup: either ViewGroupCompat.LAYOUT_MODE_CLIP_BOUNDS or ViewGroupCompat.LAYOUT_MODE_OPTICAL_BOUNDS.

If no layoutMode was explicitly set, either programmatically or in an XML resource, the method returns the layoutMode of the view's parent ViewGroup if such a parent exists, otherwise the method returns a default value of ViewGroupCompat.LAYOUT_MODE_CLIP_BOUNDS.

Returns:

the layout mode to use during layout operations

See also: ViewGroupCompat.setLayoutMode(ViewGroup, int)

public static void setLayoutMode(ViewGroup group, int mode)

Sets the basis of alignment during the layout of this ViewGroup. Valid values are either ViewGroupCompat.LAYOUT_MODE_CLIP_BOUNDS or ViewGroupCompat.LAYOUT_MODE_OPTICAL_BOUNDS.

Parameters:

mode: the layout mode to use during layout operations

See also: ViewGroupCompat.getLayoutMode(ViewGroup)

public static void setTransitionGroup(ViewGroup group, boolean isTransitionGroup)

Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions.

Parameters:

isTransitionGroup: Whether or not the ViewGroup should be treated as a unit in Activity transitions. If false, the ViewGroup won't transition, only its children. If true, the entire ViewGroup will transition together.

public static boolean isTransitionGroup(ViewGroup group)

Returns true if this ViewGroup should be considered as a single entity for removal when executing an Activity transition. If this is false, child elements will move individually during the transition.

public static int getNestedScrollAxes(ViewGroup group)

Return the current axes of nested scrolling for this ViewGroup.

A ViewGroup returning something other than ViewCompat.SCROLL_AXIS_NONE is currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.

Returns:

Flags indicating the current axes of nested scrolling

See also: ViewCompat.SCROLL_AXIS_HORIZONTAL, ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.SCROLL_AXIS_NONE

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.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;

import androidx.annotation.DoNotInline;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.R;
import androidx.core.view.ViewCompat.ScrollAxis;

/**
 * Helper for accessing features in {@link ViewGroup}.
 */
public final class ViewGroupCompat {

    /**
     * This constant is a {@link #setLayoutMode(ViewGroup, int) layoutMode}.
     * Clip bounds are the raw values of {@link View#getLeft() left},
     * {@link View#getTop() top},
     * {@link View#getRight() right} and {@link View#getBottom() bottom}.
     */
    public static final int LAYOUT_MODE_CLIP_BOUNDS = 0;

    /**
     * This constant is a {@link #setLayoutMode(ViewGroup, int) layoutMode}.
     * Optical bounds describe where a widget appears to be. They sit inside the clip
     * bounds which need to cover a larger area to allow other effects,
     * such as shadows and glows, to be drawn.
     */
    public static final int LAYOUT_MODE_OPTICAL_BOUNDS = 1;

    /*
     * Hide the constructor.
     */
    private ViewGroupCompat() {}

    /**
     * Called when a child has requested sending an {@link AccessibilityEvent} and
     * gives an opportunity to its parent to augment the event.
     * <p>
     * If an {@link AccessibilityDelegateCompat} has been specified via calling
     * {@link ViewCompat#setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its
     * {@link AccessibilityDelegateCompat#onRequestSendAccessibilityEvent(ViewGroup, View,
     * AccessibilityEvent)} is responsible for handling this call.
     * </p>
     *
     * @param group The group whose method to invoke.
     * @param child The child which requests sending the event.
     * @param event The event to be sent.
     * @return True if the event should be sent.
     *
     * @deprecated Use {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)}
     * directly.
     */
    @Deprecated
    public static boolean onRequestSendAccessibilityEvent(ViewGroup group, View child,
            AccessibilityEvent event) {
        return group.onRequestSendAccessibilityEvent(child, event);
    }

    /**
     * Enable or disable the splitting of MotionEvents to multiple children during touch event
     * dispatch. This behavior is enabled by default for applications that target an
     * SDK version of 11 (Honeycomb) or newer. On earlier platform versions this feature
     * was not supported and this method is a no-op.
     *
     * <p>When this option is enabled MotionEvents may be split and dispatched to different child
     * views depending on where each pointer initially went down. This allows for user interactions
     * such as scrolling two panes of content independently, chording of buttons, and performing
     * independent gestures on different pieces of content.
     *
     * @param group ViewGroup to modify
     * @param split <code>true</code> to allow MotionEvents to be split and dispatched to multiple
     *              child views. <code>false</code> to only allow one child view to be the target of
     *              any MotionEvent received by this ViewGroup.
     *
     * @deprecated Use {@link ViewGroup#setMotionEventSplittingEnabled(boolean)} directly.
     */
    @Deprecated
    public static void setMotionEventSplittingEnabled(ViewGroup group, boolean split) {
        group.setMotionEventSplittingEnabled(split);
    }

    /**
     * Returns the basis of alignment during layout operations on this ViewGroup:
     * either {@link #LAYOUT_MODE_CLIP_BOUNDS} or {@link #LAYOUT_MODE_OPTICAL_BOUNDS}.
     * <p>
     * If no layoutMode was explicitly set, either programmatically or in an XML resource,
     * the method returns the layoutMode of the view's parent ViewGroup if such a parent exists,
     * otherwise the method returns a default value of {@link #LAYOUT_MODE_CLIP_BOUNDS}.
     *
     * @return the layout mode to use during layout operations
     *
     * @see #setLayoutMode(ViewGroup, int)
     */
    public static int getLayoutMode(@NonNull ViewGroup group) {
        if (Build.VERSION.SDK_INT >= 18) {
            return Api18Impl.getLayoutMode(group);
        }
        return LAYOUT_MODE_CLIP_BOUNDS;
    }

    /**
     * Sets the basis of alignment during the layout of this ViewGroup.
     * Valid values are either {@link #LAYOUT_MODE_CLIP_BOUNDS} or
     * {@link #LAYOUT_MODE_OPTICAL_BOUNDS}.
     *
     * @param mode the layout mode to use during layout operations
     *
     * @see #getLayoutMode(ViewGroup)
     */
    public static void setLayoutMode(@NonNull ViewGroup group, int mode) {
        if (Build.VERSION.SDK_INT >= 18) {
            Api18Impl.setLayoutMode(group, mode);
        }
    }

    /**
     * Changes whether or not this ViewGroup should be treated as a single entity during
     * Activity Transitions.
     * @param isTransitionGroup Whether or not the ViewGroup should be treated as a unit
     *                          in Activity transitions. If false, the ViewGroup won't transition,
     *                          only its children. If true, the entire ViewGroup will transition
     *                          together.
     */
    public static void setTransitionGroup(@NonNull ViewGroup group, boolean isTransitionGroup) {
        if (Build.VERSION.SDK_INT >= 21) {
            Api21Impl.setTransitionGroup(group, isTransitionGroup);
        } else {
            group.setTag(R.id.tag_transition_group, isTransitionGroup);
        }
    }

    /**
     * Returns true if this ViewGroup should be considered as a single entity for removal
     * when executing an Activity transition. If this is false, child elements will move
     * individually during the transition.
     */
    public static boolean isTransitionGroup(@NonNull ViewGroup group) {
        if (Build.VERSION.SDK_INT >= 21) {
            return Api21Impl.isTransitionGroup(group);
        }
        Boolean explicit = (Boolean) group.getTag(R.id.tag_transition_group);
        return (explicit != null && explicit)
                || group.getBackground() != null
                || ViewCompat.getTransitionName(group) != null;
    }

    /**
     * Return the current axes of nested scrolling for this ViewGroup.
     *
     * <p>A ViewGroup returning something other than {@link ViewCompat#SCROLL_AXIS_NONE} is
     * currently acting as a nested scrolling parent for one or more descendant views in
     * the hierarchy.</p>
     *
     * @return Flags indicating the current axes of nested scrolling
     * @see ViewCompat#SCROLL_AXIS_HORIZONTAL
     * @see ViewCompat#SCROLL_AXIS_VERTICAL
     * @see ViewCompat#SCROLL_AXIS_NONE
     */
    @ScrollAxis
    @SuppressWarnings("RedundantCast") // Intentionally invoking interface method.
    public static int getNestedScrollAxes(@NonNull ViewGroup group) {
        if (Build.VERSION.SDK_INT >= 21) {
            return Api21Impl.getNestedScrollAxes(group);
        }
        if (group instanceof NestedScrollingParent) {
            return ((NestedScrollingParent) group).getNestedScrollAxes();
        }
        return ViewCompat.SCROLL_AXIS_NONE;
    }

    @RequiresApi(18)
    static class Api18Impl {
        private Api18Impl() {
            // This class is not instantiable.
        }

        @DoNotInline
        static int getLayoutMode(ViewGroup viewGroup) {
            return viewGroup.getLayoutMode();
        }

        @DoNotInline
        static void setLayoutMode(ViewGroup viewGroup, int layoutMode) {
            viewGroup.setLayoutMode(layoutMode);
        }
    }

    @RequiresApi(21)
    static class Api21Impl {
        private Api21Impl() {
            // This class is not instantiable.
        }

        @DoNotInline
        static void setTransitionGroup(ViewGroup viewGroup, boolean isTransitionGroup) {
            viewGroup.setTransitionGroup(isTransitionGroup);
        }

        @DoNotInline
        static boolean isTransitionGroup(ViewGroup viewGroup) {
            return viewGroup.isTransitionGroup();
        }

        @DoNotInline
        static int getNestedScrollAxes(ViewGroup viewGroup) {
            return viewGroup.getNestedScrollAxes();
        }
    }
}