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 @SuppressWarnings("unused") 27 private static final String TAG = "StackLayout"; 28 StackLayout(Context context, AttributeSet attrs)29 public StackLayout(Context context, AttributeSet attrs) { 30 super(context, attrs); 31 } 32 33 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)34 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 35 final int count = getChildCount(); 36 37 // Measure only the first child. 38 final View child = getChildAt(0); 39 measureChild(child, widthMeasureSpec, heightMeasureSpec); 40 41 // Ignore the paddings. 42 int width = child.getMeasuredWidth(); 43 int height = child.getMeasuredHeight(); 44 45 setMeasuredDimension(resolveSize(width, widthMeasureSpec), 46 resolveSize(height, heightMeasureSpec)); 47 } 48 49 @Override onLayout(boolean changed, int l, int t, int r, int b)50 protected void onLayout(boolean changed, int l, int t, int r, int b) { 51 final int count = super.getChildCount(); 52 53 for (int i = 0; i < count; i++) { 54 final View child = getChildAt(i); 55 if (child.getVisibility() != View.GONE) { 56 child.layout(0, 0, r - l, b - t); 57 } 58 } 59 } 60 } 61