blob: 3570c79430a44b5abe7b143693c5a7f9e5d51fd1 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Alan Viverettebd53c982016-03-31 16:55:06 -040019import android.annotation.AttrRes;
Alan Viverette96ccd392015-01-30 15:55:48 -080020import android.annotation.NonNull;
Alan Viverette91174362014-06-17 14:51:45 -070021import android.annotation.Nullable;
Alan Viverettebd53c982016-03-31 16:55:06 -040022import android.annotation.StyleRes;
Mathew Inwood978c6e22018-08-21 15:58:55 +010023import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.Context;
25import android.content.res.TypedArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.graphics.Rect;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.graphics.drawable.Drawable;
28import android.util.AttributeSet;
Fabrice Di Megliode35cee2011-06-01 15:13:50 -070029import android.view.Gravity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.view.View;
Dianne Hackborn958b9ad2009-03-31 18:00:36 -070031import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.view.ViewGroup;
Siva Velusamy94a6d152015-05-05 15:07:00 -070033import android.view.ViewHierarchyEncoder;
Ashley Rose55f9f922019-01-28 19:29:36 -050034import android.view.inspector.InspectableProperty;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.widget.RemoteViews.RemoteView;
36
Aurimas Liutikas99441c52016-10-11 16:48:32 -070037import com.android.internal.R;
38
Alan Viverettebd53c982016-03-31 16:55:06 -040039import java.util.ArrayList;
Chet Haase4610eef2015-12-03 07:38:11 -080040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041/**
42 * FrameLayout is designed to block out an area on the screen to display
Scott Main812634c22011-07-27 13:22:35 -070043 * a single item. Generally, FrameLayout should be used to hold a single child view, because it can
44 * be difficult to organize child views in a way that's scalable to different screen sizes without
45 * the children overlapping each other. You can, however, add multiple children to a FrameLayout
46 * and control their position within the FrameLayout by assigning gravity to each child, using the
47 * <a href="FrameLayout.LayoutParams.html#attr_android:layout_gravity">{@code
48 * android:layout_gravity}</a> attribute.
49 * <p>Child views are drawn in a stack, with the most recently added child on top.
50 * The size of the FrameLayout is the size of its largest child (plus padding), visible
51 * or not (if the FrameLayout's parent permits). Views that are {@link android.view.View#GONE} are
52 * used for sizing
53 * only if {@link #setMeasureAllChildren(boolean) setConsiderGoneChildrenWhenMeasuring()}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 * is set to true.
55 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 * @attr ref android.R.styleable#FrameLayout_measureAllChildren
57 */
58@RemoteView
59public class FrameLayout extends ViewGroup {
Fabrice Di Meglioaac0d4e2012-07-19 19:21:26 -070060 private static final int DEFAULT_CHILD_GRAVITY = Gravity.TOP | Gravity.START;
Romain Guy9c957372011-01-04 17:39:43 -080061
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070062 @ViewDebug.ExportedProperty(category = "measurement")
Mathew Inwood978c6e22018-08-21 15:58:55 +010063 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 boolean mMeasureAllChildren = false;
65
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070066 @ViewDebug.ExportedProperty(category = "padding")
Mathew Inwood978c6e22018-08-21 15:58:55 +010067 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 private int mForegroundPaddingLeft = 0;
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070069
70 @ViewDebug.ExportedProperty(category = "padding")
Mathew Inwood978c6e22018-08-21 15:58:55 +010071 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 private int mForegroundPaddingTop = 0;
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070073
74 @ViewDebug.ExportedProperty(category = "padding")
Mathew Inwood978c6e22018-08-21 15:58:55 +010075 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 private int mForegroundPaddingRight = 0;
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070077
78 @ViewDebug.ExportedProperty(category = "padding")
Mathew Inwood978c6e22018-08-21 15:58:55 +010079 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 private int mForegroundPaddingBottom = 0;
81
Alan Viverettebd53c982016-03-31 16:55:06 -040082 private final ArrayList<View> mMatchParentChildren = new ArrayList<>(1);
83
84 public FrameLayout(@NonNull Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 super(context);
86 }
Alan Viverettebd53c982016-03-31 16:55:06 -040087
88 public FrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 this(context, attrs, 0);
90 }
91
Alan Viverettebd53c982016-03-31 16:55:06 -040092 public FrameLayout(@NonNull Context context, @Nullable AttributeSet attrs,
93 @AttrRes int defStyleAttr) {
Alan Viverette617feb92013-09-09 18:09:13 -070094 this(context, attrs, defStyleAttr, 0);
95 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096
Alan Viverettebd53c982016-03-31 16:55:06 -040097 public FrameLayout(@NonNull Context context, @Nullable AttributeSet attrs,
98 @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
Alan Viverette617feb92013-09-09 18:09:13 -070099 super(context, attrs, defStyleAttr, defStyleRes);
100
101 final TypedArray a = context.obtainStyledAttributes(
Alan Viverettebd53c982016-03-31 16:55:06 -0400102 attrs, R.styleable.FrameLayout, defStyleAttr, defStyleRes);
Aurimas Liutikasab324cf2019-02-07 16:46:38 -0800103 saveAttributeDataForStyleable(context, R.styleable.FrameLayout,
104 attrs, a, defStyleAttr, defStyleRes);
Alan Viverettebd53c982016-03-31 16:55:06 -0400105
106 if (a.getBoolean(R.styleable.FrameLayout_measureAllChildren, false)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 setMeasureAllChildren(true);
108 }
109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 a.recycle();
Philip Milne1018fb42012-03-13 12:00:04 -0700111 }
112
113 /**
Fabrice Di Meglio9e3b0022011-06-06 16:30:29 -0700114 * Describes how the foreground is positioned. Defaults to START and TOP.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 *
116 * @param foregroundGravity See {@link android.view.Gravity}
117 *
Philip Milne1018fb42012-03-13 12:00:04 -0700118 * @see #getForegroundGravity()
119 *
Adam Powell2b25e2e2015-03-23 16:33:32 -0700120 * @attr ref android.R.styleable#View_foregroundGravity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 */
122 @android.view.RemotableViewMethod
123 public void setForegroundGravity(int foregroundGravity) {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700124 if (getForegroundGravity() != foregroundGravity) {
125 super.setForegroundGravity(foregroundGravity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126
Adam Powell2b25e2e2015-03-23 16:33:32 -0700127 // calling get* again here because the set above may apply default constraints
128 final Drawable foreground = getForeground();
129 if (getForegroundGravity() == Gravity.FILL && foreground != null) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700130 Rect padding = new Rect();
Adam Powell2b25e2e2015-03-23 16:33:32 -0700131 if (foreground.getPadding(padding)) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700132 mForegroundPaddingLeft = padding.left;
133 mForegroundPaddingTop = padding.top;
134 mForegroundPaddingRight = padding.right;
135 mForegroundPaddingBottom = padding.bottom;
136 }
137 } else {
138 mForegroundPaddingLeft = 0;
139 mForegroundPaddingTop = 0;
140 mForegroundPaddingRight = 0;
141 mForegroundPaddingBottom = 0;
142 }
143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 requestLayout();
145 }
146 }
147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 /**
149 * Returns a set of layout parameters with a width of
Romain Guy980a9382010-01-08 15:06:28 -0800150 * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT},
151 * and a height of {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 */
153 @Override
154 protected LayoutParams generateDefaultLayoutParams() {
Romain Guy980a9382010-01-08 15:06:28 -0800155 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 }
157
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700158 int getPaddingLeftWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700159 return isForegroundInsidePadding() ? Math.max(mPaddingLeft, mForegroundPaddingLeft) :
Michael Jurka02473da2011-09-08 18:26:23 -0700160 mPaddingLeft + mForegroundPaddingLeft;
161 }
162
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700163 int getPaddingRightWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700164 return isForegroundInsidePadding() ? Math.max(mPaddingRight, mForegroundPaddingRight) :
Michael Jurka02473da2011-09-08 18:26:23 -0700165 mPaddingRight + mForegroundPaddingRight;
166 }
167
168 private int getPaddingTopWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700169 return isForegroundInsidePadding() ? Math.max(mPaddingTop, mForegroundPaddingTop) :
Michael Jurka02473da2011-09-08 18:26:23 -0700170 mPaddingTop + mForegroundPaddingTop;
171 }
172
173 private int getPaddingBottomWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700174 return isForegroundInsidePadding() ? Math.max(mPaddingBottom, mForegroundPaddingBottom) :
Michael Jurka02473da2011-09-08 18:26:23 -0700175 mPaddingBottom + mForegroundPaddingBottom;
176 }
177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 @Override
179 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Romain Guy9c957372011-01-04 17:39:43 -0800180 int count = getChildCount();
181
182 final boolean measureMatchParentChildren =
183 MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY ||
184 MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
185 mMatchParentChildren.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186
187 int maxHeight = 0;
188 int maxWidth = 0;
Dianne Hackborn189ee182010-12-02 21:48:53 -0800189 int childState = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 for (int i = 0; i < count; i++) {
192 final View child = getChildAt(i);
193 if (mMeasureAllChildren || child.getVisibility() != GONE) {
194 measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
Adam Powell2b6be702011-01-08 16:44:07 -0800195 final LayoutParams lp = (LayoutParams) child.getLayoutParams();
196 maxWidth = Math.max(maxWidth,
197 child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
198 maxHeight = Math.max(maxHeight,
199 child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
Dianne Hackborn189ee182010-12-02 21:48:53 -0800200 childState = combineMeasuredStates(childState, child.getMeasuredState());
Romain Guy9c957372011-01-04 17:39:43 -0800201 if (measureMatchParentChildren) {
Romain Guy9c957372011-01-04 17:39:43 -0800202 if (lp.width == LayoutParams.MATCH_PARENT ||
203 lp.height == LayoutParams.MATCH_PARENT) {
204 mMatchParentChildren.add(child);
205 }
206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208 }
209
210 // Account for padding too
Michael Jurka02473da2011-09-08 18:26:23 -0700211 maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground();
212 maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213
214 // Check against our minimum height and width
215 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
216 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
217
218 // Check against our foreground's minimum height and width
219 final Drawable drawable = getForeground();
220 if (drawable != null) {
221 maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
222 maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
223 }
224
Dianne Hackborn189ee182010-12-02 21:48:53 -0800225 setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
226 resolveSizeAndState(maxHeight, heightMeasureSpec,
Romain Guy9c957372011-01-04 17:39:43 -0800227 childState << MEASURED_HEIGHT_STATE_SHIFT));
228
Romain Guya174d7a2011-01-07 13:27:39 -0800229 count = mMatchParentChildren.size();
230 if (count > 1) {
Romain Guy9c957372011-01-04 17:39:43 -0800231 for (int i = 0; i < count; i++) {
232 final View child = mMatchParentChildren.get(i);
Romain Guy9c957372011-01-04 17:39:43 -0800233 final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
Alan Viverette39fd9022015-06-25 12:24:27 -0700234
235 final int childWidthMeasureSpec;
Romain Guy9c957372011-01-04 17:39:43 -0800236 if (lp.width == LayoutParams.MATCH_PARENT) {
Alan Viverette39fd9022015-06-25 12:24:27 -0700237 final int width = Math.max(0, getMeasuredWidth()
238 - getPaddingLeftWithForeground() - getPaddingRightWithForeground()
239 - lp.leftMargin - lp.rightMargin);
240 childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
241 width, MeasureSpec.EXACTLY);
Romain Guy9c957372011-01-04 17:39:43 -0800242 } else {
243 childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
Michael Jurka02473da2011-09-08 18:26:23 -0700244 getPaddingLeftWithForeground() + getPaddingRightWithForeground() +
245 lp.leftMargin + lp.rightMargin,
Romain Guy9c957372011-01-04 17:39:43 -0800246 lp.width);
247 }
Alan Viverette39fd9022015-06-25 12:24:27 -0700248
249 final int childHeightMeasureSpec;
Romain Guy9c957372011-01-04 17:39:43 -0800250 if (lp.height == LayoutParams.MATCH_PARENT) {
Alan Viverette39fd9022015-06-25 12:24:27 -0700251 final int height = Math.max(0, getMeasuredHeight()
252 - getPaddingTopWithForeground() - getPaddingBottomWithForeground()
253 - lp.topMargin - lp.bottomMargin);
254 childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
255 height, MeasureSpec.EXACTLY);
Romain Guy9c957372011-01-04 17:39:43 -0800256 } else {
Romain Guycf70dcb2011-01-07 11:03:20 -0800257 childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
Michael Jurka02473da2011-09-08 18:26:23 -0700258 getPaddingTopWithForeground() + getPaddingBottomWithForeground() +
259 lp.topMargin + lp.bottomMargin,
Romain Guy9c957372011-01-04 17:39:43 -0800260 lp.height);
261 }
262
263 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
264 }
265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 }
Alan Viverettebd53c982016-03-31 16:55:06 -0400267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 @Override
269 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700270 layoutChildren(left, top, right, bottom, false /* no force left gravity */);
271 }
272
Alan Viverettebd53c982016-03-31 16:55:06 -0400273 void layoutChildren(int left, int top, int right, int bottom, boolean forceLeftGravity) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final int count = getChildCount();
275
Michael Jurka02473da2011-09-08 18:26:23 -0700276 final int parentLeft = getPaddingLeftWithForeground();
277 final int parentRight = right - left - getPaddingRightWithForeground();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278
Michael Jurka02473da2011-09-08 18:26:23 -0700279 final int parentTop = getPaddingTopWithForeground();
280 final int parentBottom = bottom - top - getPaddingBottomWithForeground();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281
282 for (int i = 0; i < count; i++) {
283 final View child = getChildAt(i);
284 if (child.getVisibility() != GONE) {
285 final LayoutParams lp = (LayoutParams) child.getLayoutParams();
286
287 final int width = child.getMeasuredWidth();
288 final int height = child.getMeasuredHeight();
289
Romain Guy9c957372011-01-04 17:39:43 -0800290 int childLeft;
291 int childTop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292
Adam Powell5e0ae672010-12-06 21:33:04 -0800293 int gravity = lp.gravity;
294 if (gravity == -1) {
295 gravity = DEFAULT_CHILD_GRAVITY;
296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297
Fabrice Di Meglioe56ffdc2012-09-23 14:51:16 -0700298 final int layoutDirection = getLayoutDirection();
Fabrice Di Meglioc0053222011-06-13 12:16:51 -0700299 final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
Adam Powell5e0ae672010-12-06 21:33:04 -0800300 final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301
Fabrice Di Megliode35cee2011-06-01 15:13:50 -0700302 switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
Adam Powell5e0ae672010-12-06 21:33:04 -0800303 case Gravity.CENTER_HORIZONTAL:
304 childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
305 lp.leftMargin - lp.rightMargin;
306 break;
307 case Gravity.RIGHT:
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700308 if (!forceLeftGravity) {
309 childLeft = parentRight - width - lp.rightMargin;
310 break;
311 }
312 case Gravity.LEFT:
Adam Powell5e0ae672010-12-06 21:33:04 -0800313 default:
314 childLeft = parentLeft + lp.leftMargin;
315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316
Adam Powell5e0ae672010-12-06 21:33:04 -0800317 switch (verticalGravity) {
318 case Gravity.TOP:
319 childTop = parentTop + lp.topMargin;
320 break;
321 case Gravity.CENTER_VERTICAL:
322 childTop = parentTop + (parentBottom - parentTop - height) / 2 +
323 lp.topMargin - lp.bottomMargin;
324 break;
325 case Gravity.BOTTOM:
326 childTop = parentBottom - height - lp.bottomMargin;
327 break;
328 default:
329 childTop = parentTop + lp.topMargin;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 }
331
332 child.layout(childLeft, childTop, childLeft + width, childTop + height);
333 }
334 }
335 }
336
337 /**
Steve Blockb25825a2011-04-27 14:51:38 +0100338 * Sets whether to consider all children, or just those in
339 * the VISIBLE or INVISIBLE state, when measuring. Defaults to false.
340 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * @param measureAll true to consider children marked GONE, false otherwise.
342 * Default value is false.
Steve Blockb25825a2011-04-27 14:51:38 +0100343 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 * @attr ref android.R.styleable#FrameLayout_measureAllChildren
345 */
346 @android.view.RemotableViewMethod
347 public void setMeasureAllChildren(boolean measureAll) {
348 mMeasureAllChildren = measureAll;
349 }
Steve Blockb25825a2011-04-27 14:51:38 +0100350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 /**
Steve Blockb25825a2011-04-27 14:51:38 +0100352 * Determines whether all children, or just those in the VISIBLE or
353 * INVISIBLE state, are considered when measuring.
354 *
355 * @return Whether all children are considered when measuring.
356 *
357 * @deprecated This method is deprecated in favor of
358 * {@link #getMeasureAllChildren() getMeasureAllChildren()}, which was
359 * renamed for consistency with
360 * {@link #setMeasureAllChildren(boolean) setMeasureAllChildren()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 */
Steve Blockb25825a2011-04-27 14:51:38 +0100362 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 public boolean getConsiderGoneChildrenWhenMeasuring() {
Steve Blockb25825a2011-04-27 14:51:38 +0100364 return getMeasureAllChildren();
365 }
366
367 /**
368 * Determines whether all children, or just those in the VISIBLE or
369 * INVISIBLE state, are considered when measuring.
370 *
371 * @return Whether all children are considered when measuring.
372 */
Ashley Rose55f9f922019-01-28 19:29:36 -0500373 @InspectableProperty
Steve Blockb25825a2011-04-27 14:51:38 +0100374 public boolean getMeasureAllChildren() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 return mMeasureAllChildren;
376 }
377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 @Override
379 public LayoutParams generateLayoutParams(AttributeSet attrs) {
Alan Viverettebd53c982016-03-31 16:55:06 -0400380 return new FrameLayout.LayoutParams(getContext(), attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
382
Patrick Dubroye0a799a2011-05-04 16:19:22 -0700383 @Override
384 public boolean shouldDelayChildPressedState() {
385 return false;
386 }
387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 @Override
389 protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
390 return p instanceof LayoutParams;
391 }
392
393 @Override
Yigit Boyar885c50b2016-03-22 16:53:42 -0700394 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
Yigit Boyar2dd20a62016-08-01 17:42:28 -0700395 if (sPreserveMarginParamsInLayoutParamConversion) {
396 if (lp instanceof LayoutParams) {
397 return new LayoutParams((LayoutParams) lp);
398 } else if (lp instanceof MarginLayoutParams) {
399 return new LayoutParams((MarginLayoutParams) lp);
400 }
Yigit Boyar885c50b2016-03-22 16:53:42 -0700401 }
Yigit Boyar2dd20a62016-08-01 17:42:28 -0700402 return new LayoutParams(lp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 }
404
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800405 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -0800406 public CharSequence getAccessibilityClassName() {
407 return FrameLayout.class.getName();
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800408 }
409
Siva Velusamy94a6d152015-05-05 15:07:00 -0700410 /** @hide */
411 @Override
412 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
413 super.encodeProperties(encoder);
414
415 encoder.addProperty("measurement:measureAllChildren", mMeasureAllChildren);
416 encoder.addProperty("padding:foregroundPaddingLeft", mForegroundPaddingLeft);
417 encoder.addProperty("padding:foregroundPaddingTop", mForegroundPaddingTop);
418 encoder.addProperty("padding:foregroundPaddingRight", mForegroundPaddingRight);
419 encoder.addProperty("padding:foregroundPaddingBottom", mForegroundPaddingBottom);
420 }
421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 /**
423 * Per-child layout information for layouts that support margins.
424 * See {@link android.R.styleable#FrameLayout_Layout FrameLayout Layout Attributes}
425 * for a list of all child view attributes that this class supports.
Alan Viverettebd53c982016-03-31 16:55:06 -0400426 *
Romain Guy606e8cc2010-08-17 12:43:05 -0700427 * @attr ref android.R.styleable#FrameLayout_Layout_layout_gravity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 */
429 public static class LayoutParams extends MarginLayoutParams {
430 /**
Alan Viverette2b4b335d2016-04-15 11:10:28 -0400431 * Value for {@link #gravity} indicating that a gravity has not been
432 * explicitly specified.
433 */
434 public static final int UNSPECIFIED_GRAVITY = -1;
435
436 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 * The gravity to apply with the View to which these layout parameters
438 * are associated.
Alan Viverettebd53c982016-03-31 16:55:06 -0400439 * <p>
Alan Viverette2b4b335d2016-04-15 11:10:28 -0400440 * The default value is {@link #UNSPECIFIED_GRAVITY}, which is treated
441 * by FrameLayout as {@code Gravity.TOP | Gravity.START}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 *
443 * @see android.view.Gravity
Romain Guy606e8cc2010-08-17 12:43:05 -0700444 * @attr ref android.R.styleable#FrameLayout_Layout_layout_gravity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 */
Alan Viverette2b4b335d2016-04-15 11:10:28 -0400446 public int gravity = UNSPECIFIED_GRAVITY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447
Alan Viverettebd53c982016-03-31 16:55:06 -0400448 public LayoutParams(@NonNull Context c, @Nullable AttributeSet attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 super(c, attrs);
450
Alan Viverettebd53c982016-03-31 16:55:06 -0400451 final TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.FrameLayout_Layout);
Alan Viverette2b4b335d2016-04-15 11:10:28 -0400452 gravity = a.getInt(R.styleable.FrameLayout_Layout_layout_gravity, UNSPECIFIED_GRAVITY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 a.recycle();
454 }
455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 public LayoutParams(int width, int height) {
457 super(width, height);
458 }
459
460 /**
461 * Creates a new set of layout parameters with the specified width, height
462 * and weight.
463 *
Romain Guy980a9382010-01-08 15:06:28 -0800464 * @param width the width, either {@link #MATCH_PARENT},
Alan Viverettebd53c982016-03-31 16:55:06 -0400465 * {@link #WRAP_CONTENT} or a fixed size in pixels
Romain Guy980a9382010-01-08 15:06:28 -0800466 * @param height the height, either {@link #MATCH_PARENT},
Alan Viverettebd53c982016-03-31 16:55:06 -0400467 * {@link #WRAP_CONTENT} or a fixed size in pixels
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 * @param gravity the gravity
469 *
470 * @see android.view.Gravity
471 */
472 public LayoutParams(int width, int height, int gravity) {
473 super(width, height);
474 this.gravity = gravity;
475 }
476
Alan Viverettebd53c982016-03-31 16:55:06 -0400477 public LayoutParams(@NonNull ViewGroup.LayoutParams source) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 super(source);
479 }
480
Alan Viverettebd53c982016-03-31 16:55:06 -0400481 public LayoutParams(@NonNull ViewGroup.MarginLayoutParams source) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 super(source);
483 }
Alan Viverette0a0e1552013-08-07 13:24:09 -0700484
485 /**
486 * Copy constructor. Clones the width, height, margin values, and
487 * gravity of the source.
488 *
489 * @param source The layout params to copy from.
490 */
Alan Viverettebd53c982016-03-31 16:55:06 -0400491 public LayoutParams(@NonNull LayoutParams source) {
Alan Viverette0a0e1552013-08-07 13:24:09 -0700492 super(source);
493
494 this.gravity = source.gravity;
495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
497}