1 /* 2 * Copyright (C) 2008 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 android.widget.scroll; 18 19 import android.util.ScrollViewScenario; 20 21 import android.widget.Button; 22 import android.widget.LinearLayout; 23 24 /** 25 * A series of short buttons, some of which are embedded within another 26 * layout. 27 */ 28 public class ShortButtons extends ScrollViewScenario { 29 30 private final int mNumButtons = 10; 31 protected final float mButtonHeightFactor = 0.2f; 32 getNumButtons()33 public int getNumButtons() { 34 return mNumButtons; 35 } 36 getButtonAt(int index)37 public Button getButtonAt(int index) { 38 if (index < 3) { 39 return getContentChildAt(index); 40 } else { 41 LinearLayout ll = getContentChildAt(3); 42 return (Button) ll.getChildAt(index - 3); 43 } 44 } 45 46 @Override init(Params params)47 protected void init(Params params) { 48 final int numButtonsInSubLayout = getNumButtons() - 3; 49 params.addButtons(3, "top-level", mButtonHeightFactor) 50 .addVerticalLLOfButtons("embedded", 51 numButtonsInSubLayout, 52 numButtonsInSubLayout * mButtonHeightFactor); 53 } 54 } 55