FrameLayout.java revision 96ccd39d354d8b268eac32e4cf873ea141ef5ed4
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget;
18
19import java.util.ArrayList;
20
21import android.annotation.NonNull;
22import android.annotation.Nullable;
23import android.content.Context;
24import android.content.res.ColorStateList;
25import android.content.res.TypedArray;
26import android.graphics.Canvas;
27import android.graphics.PorterDuff;
28import android.graphics.Rect;
29import android.graphics.Region;
30import android.graphics.drawable.Drawable;
31import android.util.AttributeSet;
32import android.view.Gravity;
33import android.view.RemotableViewMethod;
34import android.view.View;
35import android.view.ViewDebug;
36import android.view.ViewGroup;
37import android.view.accessibility.AccessibilityEvent;
38import android.view.accessibility.AccessibilityNodeInfo;
39import android.widget.RemoteViews.RemoteView;
40
41import com.android.internal.R;
42
43
44/**
45 * FrameLayout is designed to block out an area on the screen to display
46 * a single item. Generally, FrameLayout should be used to hold a single child view, because it can
47 * be difficult to organize child views in a way that's scalable to different screen sizes without
48 * the children overlapping each other. You can, however, add multiple children to a FrameLayout
49 * and control their position within the FrameLayout by assigning gravity to each child, using the
50 * <a href="FrameLayout.LayoutParams.html#attr_android:layout_gravity">{@code
51 * android:layout_gravity}</a> attribute.
52 * <p>Child views are drawn in a stack, with the most recently added child on top.
53 * The size of the FrameLayout is the size of its largest child (plus padding), visible
54 * or not (if the FrameLayout's parent permits). Views that are {@link android.view.View#GONE} are
55 * used for sizing
56 * only if {@link #setMeasureAllChildren(boolean) setConsiderGoneChildrenWhenMeasuring()}
57 * is set to true.
58 *
59 * @attr ref android.R.styleable#FrameLayout_foreground
60 * @attr ref android.R.styleable#FrameLayout_foregroundGravity
61 * @attr ref android.R.styleable#FrameLayout_measureAllChildren
62 */
63@RemoteView
64public class FrameLayout extends ViewGroup {
65    private static final int DEFAULT_CHILD_GRAVITY = Gravity.TOP | Gravity.START;
66
67    @ViewDebug.ExportedProperty(category = "measurement")
68    boolean mMeasureAllChildren = false;
69
70    @ViewDebug.ExportedProperty(category = "drawing")
71    private Drawable mForeground;
72    private ColorStateList mForegroundTintList = null;
73    private PorterDuff.Mode mForegroundTintMode = null;
74    private boolean mHasForegroundTint = false;
75    private boolean mHasForegroundTintMode = false;
76
77    @ViewDebug.ExportedProperty(category = "padding")
78    private int mForegroundPaddingLeft = 0;
79
80    @ViewDebug.ExportedProperty(category = "padding")
81    private int mForegroundPaddingTop = 0;
82
83    @ViewDebug.ExportedProperty(category = "padding")
84    private int mForegroundPaddingRight = 0;
85
86    @ViewDebug.ExportedProperty(category = "padding")
87    private int mForegroundPaddingBottom = 0;
88
89    private final Rect mSelfBounds = new Rect();
90    private final Rect mOverlayBounds = new Rect();
91
92    @ViewDebug.ExportedProperty(category = "drawing")
93    private int mForegroundGravity = Gravity.FILL;
94
95    /** {@hide} */
96    @ViewDebug.ExportedProperty(category = "drawing")
97    protected boolean mForegroundInPadding = true;
98
99    boolean mForegroundBoundsChanged = false;
100
101    private final ArrayList<View> mMatchParentChildren = new ArrayList<View>(1);
102
103    public FrameLayout(Context context) {
104        super(context);
105    }
106
107    public FrameLayout(Context context, AttributeSet attrs) {
108        this(context, attrs, 0);
109    }
110
111    public FrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
112        this(context, attrs, defStyleAttr, 0);
113    }
114
115    public FrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
116        super(context, attrs, defStyleAttr, defStyleRes);
117
118        final TypedArray a = context.obtainStyledAttributes(
119                attrs, com.android.internal.R.styleable.FrameLayout, defStyleAttr, defStyleRes);
120
121        mForegroundGravity = a.getInt(
122                com.android.internal.R.styleable.FrameLayout_foregroundGravity, mForegroundGravity);
123
124        final Drawable d = a.getDrawable(com.android.internal.R.styleable.FrameLayout_foreground);
125        if (d != null) {
126            setForeground(d);
127        }
128
129        if (a.getBoolean(com.android.internal.R.styleable.FrameLayout_measureAllChildren, false)) {
130            setMeasureAllChildren(true);
131        }
132
133        if (a.hasValue(R.styleable.FrameLayout_foregroundTintMode)) {
134            mForegroundTintMode = Drawable.parseTintMode(a.getInt(
135                    R.styleable.FrameLayout_foregroundTintMode, -1), mForegroundTintMode);
136            mHasForegroundTintMode = true;
137        }
138
139        if (a.hasValue(R.styleable.FrameLayout_foregroundTint)) {
140            mForegroundTintList = a.getColorStateList(R.styleable.FrameLayout_foregroundTint);
141            mHasForegroundTint = true;
142        }
143
144        mForegroundInPadding = a.getBoolean(R.styleable.FrameLayout_foregroundInsidePadding, true);
145
146        a.recycle();
147
148        applyForegroundTint();
149    }
150
151    /**
152     * Describes how the foreground is positioned.
153     *
154     * @return foreground gravity.
155     *
156     * @see #setForegroundGravity(int)
157     *
158     * @attr ref android.R.styleable#FrameLayout_foregroundGravity
159     */
160    public int getForegroundGravity() {
161        return mForegroundGravity;
162    }
163
164    /**
165     * Describes how the foreground is positioned. Defaults to START and TOP.
166     *
167     * @param foregroundGravity See {@link android.view.Gravity}
168     *
169     * @see #getForegroundGravity()
170     *
171     * @attr ref android.R.styleable#FrameLayout_foregroundGravity
172     */
173    @android.view.RemotableViewMethod
174    public void setForegroundGravity(int foregroundGravity) {
175        if (mForegroundGravity != foregroundGravity) {
176            if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
177                foregroundGravity |= Gravity.START;
178            }
179
180            if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
181                foregroundGravity |= Gravity.TOP;
182            }
183
184            mForegroundGravity = foregroundGravity;
185
186
187            if (mForegroundGravity == Gravity.FILL && mForeground != null) {
188                Rect padding = new Rect();
189                if (mForeground.getPadding(padding)) {
190                    mForegroundPaddingLeft = padding.left;
191                    mForegroundPaddingTop = padding.top;
192                    mForegroundPaddingRight = padding.right;
193                    mForegroundPaddingBottom = padding.bottom;
194                }
195            } else {
196                mForegroundPaddingLeft = 0;
197                mForegroundPaddingTop = 0;
198                mForegroundPaddingRight = 0;
199                mForegroundPaddingBottom = 0;
200            }
201
202            requestLayout();
203        }
204    }
205
206    @Override
207    protected void onVisibilityChanged(@NonNull View changedView, @Visibility int visibility) {
208        super.onVisibilityChanged(changedView, visibility);
209
210        final Drawable dr = mForeground;
211        if (dr != null) {
212            final boolean visible = visibility == VISIBLE && getVisibility() == VISIBLE;
213            if (visible != dr.isVisible()) {
214                dr.setVisible(visible, false);
215            }
216        }
217    }
218
219    /**
220     * {@inheritDoc}
221     */
222    @Override
223    protected boolean verifyDrawable(Drawable who) {
224        return super.verifyDrawable(who) || (who == mForeground);
225    }
226
227    @Override
228    public void jumpDrawablesToCurrentState() {
229        super.jumpDrawablesToCurrentState();
230        if (mForeground != null) mForeground.jumpToCurrentState();
231    }
232
233    /**
234     * {@inheritDoc}
235     */
236    @Override
237    protected void drawableStateChanged() {
238        super.drawableStateChanged();
239        if (mForeground != null && mForeground.isStateful()) {
240            mForeground.setState(getDrawableState());
241        }
242    }
243
244    @Override
245    public void drawableHotspotChanged(float x, float y) {
246        super.drawableHotspotChanged(x, y);
247
248        if (mForeground != null) {
249            mForeground.setHotspot(x, y);
250        }
251    }
252
253    /**
254     * Returns a set of layout parameters with a width of
255     * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT},
256     * and a height of {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}.
257     */
258    @Override
259    protected LayoutParams generateDefaultLayoutParams() {
260        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
261    }
262
263    /**
264     * Supply a Drawable that is to be rendered on top of all of the child
265     * views in the frame layout.  Any padding in the Drawable will be taken
266     * into account by ensuring that the children are inset to be placed
267     * inside of the padding area.
268     *
269     * @param d The Drawable to be drawn on top of the children.
270     *
271     * @attr ref android.R.styleable#FrameLayout_foreground
272     */
273    public void setForeground(Drawable d) {
274        if (mForeground != d) {
275            if (mForeground != null) {
276                mForeground.setCallback(null);
277                unscheduleDrawable(mForeground);
278            }
279
280            mForeground = d;
281            mForegroundPaddingLeft = 0;
282            mForegroundPaddingTop = 0;
283            mForegroundPaddingRight = 0;
284            mForegroundPaddingBottom = 0;
285
286            if (d != null) {
287                setWillNotDraw(false);
288                d.setCallback(this);
289                d.setLayoutDirection(getLayoutDirection());
290                if (d.isStateful()) {
291                    d.setState(getDrawableState());
292                }
293                applyForegroundTint();
294                if (mForegroundGravity == Gravity.FILL) {
295                    Rect padding = new Rect();
296                    if (d.getPadding(padding)) {
297                        mForegroundPaddingLeft = padding.left;
298                        mForegroundPaddingTop = padding.top;
299                        mForegroundPaddingRight = padding.right;
300                        mForegroundPaddingBottom = padding.bottom;
301                    }
302                }
303            }  else {
304                setWillNotDraw(true);
305            }
306            requestLayout();
307            invalidate();
308        }
309    }
310
311    /**
312     * Returns the drawable used as the foreground of this FrameLayout. The
313     * foreground drawable, if non-null, is always drawn on top of the children.
314     *
315     * @return A Drawable or null if no foreground was set.
316     */
317    public Drawable getForeground() {
318        return mForeground;
319    }
320
321    /**
322     * Applies a tint to the foreground drawable. Does not modify the current
323     * tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
324     * <p>
325     * Subsequent calls to {@link #setForeground(Drawable)} will automatically
326     * mutate the drawable and apply the specified tint and tint mode using
327     * {@link Drawable#setTintList(ColorStateList)}.
328     *
329     * @param tint the tint to apply, may be {@code null} to clear tint
330     *
331     * @attr ref android.R.styleable#FrameLayout_foregroundTint
332     * @see #getForegroundTintList()
333     * @see Drawable#setTintList(ColorStateList)
334     */
335    public void setForegroundTintList(@Nullable ColorStateList tint) {
336        mForegroundTintList = tint;
337        mHasForegroundTint = true;
338
339        applyForegroundTint();
340    }
341
342    /**
343     * @return the tint applied to the foreground drawable
344     * @attr ref android.R.styleable#FrameLayout_foregroundTint
345     * @see #setForegroundTintList(ColorStateList)
346     */
347    @Nullable
348    public ColorStateList getForegroundTintList() {
349        return mForegroundTintList;
350    }
351
352    /**
353     * Specifies the blending mode used to apply the tint specified by
354     * {@link #setForegroundTintList(ColorStateList)}} to the foreground drawable.
355     * The default mode is {@link PorterDuff.Mode#SRC_IN}.
356     *
357     * @param tintMode the blending mode used to apply the tint, may be
358     *                 {@code null} to clear tint
359     * @attr ref android.R.styleable#FrameLayout_foregroundTintMode
360     * @see #getForegroundTintMode()
361     * @see Drawable#setTintMode(PorterDuff.Mode)
362     */
363    public void setForegroundTintMode(@Nullable PorterDuff.Mode tintMode) {
364        mForegroundTintMode = tintMode;
365        mHasForegroundTintMode = true;
366
367        applyForegroundTint();
368    }
369
370    /**
371     * @return the blending mode used to apply the tint to the foreground
372     *         drawable
373     * @attr ref android.R.styleable#FrameLayout_foregroundTintMode
374     * @see #setForegroundTintMode(PorterDuff.Mode)
375     */
376    @Nullable
377    public PorterDuff.Mode getForegroundTintMode() {
378        return mForegroundTintMode;
379    }
380
381    private void applyForegroundTint() {
382        if (mForeground != null && (mHasForegroundTint || mHasForegroundTintMode)) {
383            mForeground = mForeground.mutate();
384
385            if (mHasForegroundTint) {
386                mForeground.setTintList(mForegroundTintList);
387            }
388
389            if (mHasForegroundTintMode) {
390                mForeground.setTintMode(mForegroundTintMode);
391            }
392
393            // The drawable (or one of its children) may not have been
394            // stateful before applying the tint, so let's try again.
395            if (mForeground.isStateful()) {
396                mForeground.setState(getDrawableState());
397            }
398        }
399    }
400
401    int getPaddingLeftWithForeground() {
402        return mForegroundInPadding ? Math.max(mPaddingLeft, mForegroundPaddingLeft) :
403            mPaddingLeft + mForegroundPaddingLeft;
404    }
405
406    int getPaddingRightWithForeground() {
407        return mForegroundInPadding ? Math.max(mPaddingRight, mForegroundPaddingRight) :
408            mPaddingRight + mForegroundPaddingRight;
409    }
410
411    private int getPaddingTopWithForeground() {
412        return mForegroundInPadding ? Math.max(mPaddingTop, mForegroundPaddingTop) :
413            mPaddingTop + mForegroundPaddingTop;
414    }
415
416    private int getPaddingBottomWithForeground() {
417        return mForegroundInPadding ? Math.max(mPaddingBottom, mForegroundPaddingBottom) :
418            mPaddingBottom + mForegroundPaddingBottom;
419    }
420
421
422    /**
423     * {@inheritDoc}
424     */
425    @Override
426    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
427        int count = getChildCount();
428
429        final boolean measureMatchParentChildren =
430                MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY ||
431                MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
432        mMatchParentChildren.clear();
433
434        int maxHeight = 0;
435        int maxWidth = 0;
436        int childState = 0;
437
438        for (int i = 0; i < count; i++) {
439            final View child = getChildAt(i);
440            if (mMeasureAllChildren || child.getVisibility() != GONE) {
441                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
442                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
443                maxWidth = Math.max(maxWidth,
444                        child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
445                maxHeight = Math.max(maxHeight,
446                        child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
447                childState = combineMeasuredStates(childState, child.getMeasuredState());
448                if (measureMatchParentChildren) {
449                    if (lp.width == LayoutParams.MATCH_PARENT ||
450                            lp.height == LayoutParams.MATCH_PARENT) {
451                        mMatchParentChildren.add(child);
452                    }
453                }
454            }
455        }
456
457        // Account for padding too
458        maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground();
459        maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground();
460
461        // Check against our minimum height and width
462        maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
463        maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
464
465        // Check against our foreground's minimum height and width
466        final Drawable drawable = getForeground();
467        if (drawable != null) {
468            maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
469            maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
470        }
471
472        setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
473                resolveSizeAndState(maxHeight, heightMeasureSpec,
474                        childState << MEASURED_HEIGHT_STATE_SHIFT));
475
476        count = mMatchParentChildren.size();
477        if (count > 1) {
478            for (int i = 0; i < count; i++) {
479                final View child = mMatchParentChildren.get(i);
480
481                final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
482                int childWidthMeasureSpec;
483                int childHeightMeasureSpec;
484
485                if (lp.width == LayoutParams.MATCH_PARENT) {
486                    childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth() -
487                            getPaddingLeftWithForeground() - getPaddingRightWithForeground() -
488                            lp.leftMargin - lp.rightMargin,
489                            MeasureSpec.EXACTLY);
490                } else {
491                    childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
492                            getPaddingLeftWithForeground() + getPaddingRightWithForeground() +
493                            lp.leftMargin + lp.rightMargin,
494                            lp.width);
495                }
496
497                if (lp.height == LayoutParams.MATCH_PARENT) {
498                    childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight() -
499                            getPaddingTopWithForeground() - getPaddingBottomWithForeground() -
500                            lp.topMargin - lp.bottomMargin,
501                            MeasureSpec.EXACTLY);
502                } else {
503                    childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
504                            getPaddingTopWithForeground() + getPaddingBottomWithForeground() +
505                            lp.topMargin + lp.bottomMargin,
506                            lp.height);
507                }
508
509                child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
510            }
511        }
512    }
513
514    /**
515     * {@inheritDoc}
516     */
517    @Override
518    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
519        layoutChildren(left, top, right, bottom, false /* no force left gravity */);
520    }
521
522    void layoutChildren(int left, int top, int right, int bottom,
523                                  boolean forceLeftGravity) {
524        final int count = getChildCount();
525
526        final int parentLeft = getPaddingLeftWithForeground();
527        final int parentRight = right - left - getPaddingRightWithForeground();
528
529        final int parentTop = getPaddingTopWithForeground();
530        final int parentBottom = bottom - top - getPaddingBottomWithForeground();
531
532        mForegroundBoundsChanged = true;
533
534        for (int i = 0; i < count; i++) {
535            final View child = getChildAt(i);
536            if (child.getVisibility() != GONE) {
537                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
538
539                final int width = child.getMeasuredWidth();
540                final int height = child.getMeasuredHeight();
541
542                int childLeft;
543                int childTop;
544
545                int gravity = lp.gravity;
546                if (gravity == -1) {
547                    gravity = DEFAULT_CHILD_GRAVITY;
548                }
549
550                final int layoutDirection = getLayoutDirection();
551                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
552                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
553
554                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
555                    case Gravity.CENTER_HORIZONTAL:
556                        childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
557                        lp.leftMargin - lp.rightMargin;
558                        break;
559                    case Gravity.RIGHT:
560                        if (!forceLeftGravity) {
561                            childLeft = parentRight - width - lp.rightMargin;
562                            break;
563                        }
564                    case Gravity.LEFT:
565                    default:
566                        childLeft = parentLeft + lp.leftMargin;
567                }
568
569                switch (verticalGravity) {
570                    case Gravity.TOP:
571                        childTop = parentTop + lp.topMargin;
572                        break;
573                    case Gravity.CENTER_VERTICAL:
574                        childTop = parentTop + (parentBottom - parentTop - height) / 2 +
575                        lp.topMargin - lp.bottomMargin;
576                        break;
577                    case Gravity.BOTTOM:
578                        childTop = parentBottom - height - lp.bottomMargin;
579                        break;
580                    default:
581                        childTop = parentTop + lp.topMargin;
582                }
583
584                child.layout(childLeft, childTop, childLeft + width, childTop + height);
585            }
586        }
587    }
588
589    /**
590     * {@inheritDoc}
591     */
592    @Override
593    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
594        super.onSizeChanged(w, h, oldw, oldh);
595        mForegroundBoundsChanged = true;
596    }
597
598    /**
599     * {@inheritDoc}
600     */
601    @Override
602    public void draw(Canvas canvas) {
603        super.draw(canvas);
604
605        if (mForeground != null) {
606            final Drawable foreground = mForeground;
607
608            if (mForegroundBoundsChanged) {
609                mForegroundBoundsChanged = false;
610                final Rect selfBounds = mSelfBounds;
611                final Rect overlayBounds = mOverlayBounds;
612
613                final int w = mRight-mLeft;
614                final int h = mBottom-mTop;
615
616                if (mForegroundInPadding) {
617                    selfBounds.set(0, 0, w, h);
618                } else {
619                    selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom);
620                }
621
622                final int layoutDirection = getLayoutDirection();
623                Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
624                        foreground.getIntrinsicHeight(), selfBounds, overlayBounds,
625                        layoutDirection);
626                foreground.setBounds(overlayBounds);
627            }
628
629            foreground.draw(canvas);
630        }
631    }
632
633    /**
634     * {@inheritDoc}
635     */
636    @Override
637    public boolean gatherTransparentRegion(Region region) {
638        boolean opaque = super.gatherTransparentRegion(region);
639        if (region != null && mForeground != null) {
640            applyDrawableToTransparentRegion(mForeground, region);
641        }
642        return opaque;
643    }
644
645    /**
646     * Sets whether to consider all children, or just those in
647     * the VISIBLE or INVISIBLE state, when measuring. Defaults to false.
648     *
649     * @param measureAll true to consider children marked GONE, false otherwise.
650     * Default value is false.
651     *
652     * @attr ref android.R.styleable#FrameLayout_measureAllChildren
653     */
654    @android.view.RemotableViewMethod
655    public void setMeasureAllChildren(boolean measureAll) {
656        mMeasureAllChildren = measureAll;
657    }
658
659    /**
660     * Determines whether all children, or just those in the VISIBLE or
661     * INVISIBLE state, are considered when measuring.
662     *
663     * @return Whether all children are considered when measuring.
664     *
665     * @deprecated This method is deprecated in favor of
666     * {@link #getMeasureAllChildren() getMeasureAllChildren()}, which was
667     * renamed for consistency with
668     * {@link #setMeasureAllChildren(boolean) setMeasureAllChildren()}.
669     */
670    @Deprecated
671    public boolean getConsiderGoneChildrenWhenMeasuring() {
672        return getMeasureAllChildren();
673    }
674
675    /**
676     * Determines whether all children, or just those in the VISIBLE or
677     * INVISIBLE state, are considered when measuring.
678     *
679     * @return Whether all children are considered when measuring.
680     */
681    public boolean getMeasureAllChildren() {
682        return mMeasureAllChildren;
683    }
684
685    /**
686     * {@inheritDoc}
687     */
688    @Override
689    public LayoutParams generateLayoutParams(AttributeSet attrs) {
690        return new FrameLayout.LayoutParams(getContext(), attrs);
691    }
692
693    @Override
694    public boolean shouldDelayChildPressedState() {
695        return false;
696    }
697
698    /**
699     * {@inheritDoc}
700     */
701    @Override
702    protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
703        return p instanceof LayoutParams;
704    }
705
706    @Override
707    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
708        return new LayoutParams(p);
709    }
710
711
712    /** @hide */
713    @Override
714    public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
715        super.onInitializeAccessibilityEventInternal(event);
716        event.setClassName(FrameLayout.class.getName());
717    }
718
719    /** @hide */
720    @Override
721    public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
722        super.onInitializeAccessibilityNodeInfoInternal(info);
723        info.setClassName(FrameLayout.class.getName());
724    }
725
726    /**
727     * Per-child layout information for layouts that support margins.
728     * See {@link android.R.styleable#FrameLayout_Layout FrameLayout Layout Attributes}
729     * for a list of all child view attributes that this class supports.
730     *
731     * @attr ref android.R.styleable#FrameLayout_Layout_layout_gravity
732     */
733    public static class LayoutParams extends MarginLayoutParams {
734        /**
735         * The gravity to apply with the View to which these layout parameters
736         * are associated.
737         *
738         * @see android.view.Gravity
739         *
740         * @attr ref android.R.styleable#FrameLayout_Layout_layout_gravity
741         */
742        public int gravity = -1;
743
744        /**
745         * {@inheritDoc}
746         */
747        public LayoutParams(Context c, AttributeSet attrs) {
748            super(c, attrs);
749
750            TypedArray a = c.obtainStyledAttributes(attrs, com.android.internal.R.styleable.FrameLayout_Layout);
751            gravity = a.getInt(com.android.internal.R.styleable.FrameLayout_Layout_layout_gravity, -1);
752            a.recycle();
753        }
754
755        /**
756         * {@inheritDoc}
757         */
758        public LayoutParams(int width, int height) {
759            super(width, height);
760        }
761
762        /**
763         * Creates a new set of layout parameters with the specified width, height
764         * and weight.
765         *
766         * @param width the width, either {@link #MATCH_PARENT},
767         *        {@link #WRAP_CONTENT} or a fixed size in pixels
768         * @param height the height, either {@link #MATCH_PARENT},
769         *        {@link #WRAP_CONTENT} or a fixed size in pixels
770         * @param gravity the gravity
771         *
772         * @see android.view.Gravity
773         */
774        public LayoutParams(int width, int height, int gravity) {
775            super(width, height);
776            this.gravity = gravity;
777        }
778
779        /**
780         * {@inheritDoc}
781         */
782        public LayoutParams(ViewGroup.LayoutParams source) {
783            super(source);
784        }
785
786        /**
787         * {@inheritDoc}
788         */
789        public LayoutParams(ViewGroup.MarginLayoutParams source) {
790            super(source);
791        }
792
793        /**
794         * Copy constructor. Clones the width, height, margin values, and
795         * gravity of the source.
796         *
797         * @param source The layout params to copy from.
798         */
799        public LayoutParams(LayoutParams source) {
800            super(source);
801
802            this.gravity = source.gravity;
803        }
804    }
805}
806