• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package com.android.camera.ui;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.View;
22 import android.view.ViewGroup;
23 
24 // A layout designed to make the children same size as the first child.
25 public class StackLayout extends ViewGroup {
26     private static final String TAG = "StackLayout";
27 
StackLayout(Context context, AttributeSet attrs)28     public StackLayout(Context context, AttributeSet attrs) {
29         super(context, attrs);
30     }
31 
32     @Override
onMeasure(int widthMeasureSpec, int heightMeasureSpec)33     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
34         final int count = getChildCount();
35 
36         // Measure only the first child.
37         final View child = getChildAt(0);
38         measureChild(child, widthMeasureSpec, heightMeasureSpec);
39 
40         // Ignore the paddings.
41         int width = child.getMeasuredWidth();
42         int height = child.getMeasuredHeight();
43 
44         setMeasuredDimension(resolveSize(width, widthMeasureSpec),
45                 resolveSize(height, heightMeasureSpec));
46     }
47 
48     @Override
onLayout(boolean changed, int l, int t, int r, int b)49     protected void onLayout(boolean changed, int l, int t, int r, int b) {
50         final int count = super.getChildCount();
51 
52         for (int i = 0; i < count; i++) {
53             final View child = getChildAt(i);
54             if (child.getVisibility() != View.GONE) {
55                 child.layout(0, 0, r - l, b - t);
56             }
57         }
58     }
59 }
60