1 /* 2 * Copyright (C) 2010 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.graphics.Rect; 20 import android.view.View.MeasureSpec; 21 22 class LinearLayout extends GLView { 23 24 @Override 25 protected void onMeasure(int widthSpec, int heightSpec) { 26 int width = 0; 27 int height = 0; 28 for (int i = 0, n = getComponentCount(); i < n; ++i) { 29 GLView view = getComponent(i); 30 view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 31 width = Math.max(width, view.getMeasuredWidth()); 32 height += view.getMeasuredHeight(); 33 } 34 new MeasureHelper(this) 35 .setPreferredContentSize(width, height) 36 .measure(widthSpec, heightSpec); 37 } 38 39 @Override 40 protected void onLayout(boolean changed, int l, int t, int r, int b) { 41 Rect p = mPaddings; 42 int offsetX = p.left; 43 int width = (r - l) - p.left - p.right; 44 int offsetY = p.top; 45 for (int i = 0, n = getComponentCount(); i < n; ++i) { 46 GLView view = getComponent(i); 47 view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 48 int nextOffsetY = offsetY + view.getMeasuredHeight(); 49 view.layout(offsetX, offsetY, offsetX + width, nextOffsetY); 50 offsetY = nextOffsetY; 51 } 52 } 53 54 } 55