• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.support.v17.leanback.widget;
15 
16 import android.content.Context;
17 import android.util.AttributeSet;
18 import android.view.View;
19 import android.widget.FrameLayout;
20 
21 /**
22  * Customized FrameLayout excludes margin of child from calculating the child size.
23  * So we can change left margin of rows while keep the width of rows unchanged without
24  * using hardcoded DIPS.
25  * @hide
26  */
27 public class BrowseRowsFrameLayout extends FrameLayout {
28 
BrowseRowsFrameLayout(Context context)29     public BrowseRowsFrameLayout(Context context) {
30         this(context ,null);
31     }
32 
BrowseRowsFrameLayout(Context context, AttributeSet attrs)33     public BrowseRowsFrameLayout(Context context, AttributeSet attrs) {
34         this(context, attrs, 0);
35     }
36 
BrowseRowsFrameLayout(Context context, AttributeSet attrs, int defStyle)37     public BrowseRowsFrameLayout(Context context, AttributeSet attrs,
38             int defStyle) {
39         super(context, attrs, defStyle);
40     }
41 
42     @Override
measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)43     protected void measureChildWithMargins(View child,
44             int parentWidthMeasureSpec, int widthUsed,
45             int parentHeightMeasureSpec, int heightUsed) {
46         final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
47         final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
48                 getPaddingLeft() + getPaddingRight() + widthUsed, lp.width);
49         final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec,
50                 getPaddingTop() + getPaddingBottom() + heightUsed, lp.height);
51         child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
52     }
53 
54 }
55