1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package androidx.leanback.widget; 15 16 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; 17 18 import android.content.Context; 19 import android.util.AttributeSet; 20 import android.view.View; 21 import android.widget.FrameLayout; 22 23 import androidx.annotation.RestrictTo; 24 25 /** 26 * Customized FrameLayout excludes margin of child from calculating the child size. 27 * So we can change left margin of rows while keep the width of rows unchanged without 28 * using hardcoded DIPS. 29 * @hide 30 */ 31 @RestrictTo(LIBRARY_GROUP) 32 public class BrowseRowsFrameLayout extends FrameLayout { 33 34 public BrowseRowsFrameLayout(Context context) { 35 this(context ,null); 36 } 37 38 public BrowseRowsFrameLayout(Context context, AttributeSet attrs) { 39 this(context, attrs, 0); 40 } 41 42 public BrowseRowsFrameLayout(Context context, AttributeSet attrs, 43 int defStyle) { 44 super(context, attrs, defStyle); 45 } 46 47 @Override 48 protected void measureChildWithMargins(View child, 49 int parentWidthMeasureSpec, int widthUsed, 50 int parentHeightMeasureSpec, int heightUsed) { 51 final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); 52 final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, 53 getPaddingLeft() + getPaddingRight() + widthUsed, lp.width); 54 final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, 55 getPaddingTop() + getPaddingBottom() + heightUsed, lp.height); 56 child.measure(childWidthMeasureSpec, childHeightMeasureSpec); 57 } 58 59 } 60