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