1 /* 2 * Copyright (C) 2007 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.app.Activity; 20 import android.os.Bundle; 21 import android.widget.Button; 22 import android.widget.LinearLayout; 23 import android.widget.ScrollView; 24 import android.widget.TextView; 25 26 import com.android.frameworks.coretests.R; 27 28 /** 29 * Basic scroll view example 30 */ 31 public class ScrollViewButtonsAndLabels extends Activity { 32 33 private ScrollView mScrollView; 34 private LinearLayout mLinearLayout; 35 36 private int mNumGroups = 10; 37 38 getScrollView()39 public ScrollView getScrollView() { 40 return mScrollView; 41 } 42 getLinearLayout()43 public LinearLayout getLinearLayout() { 44 return mLinearLayout; 45 } 46 getNumButtons()47 public int getNumButtons() { 48 return mNumGroups; 49 } 50 getButton(int groupNum)51 public Button getButton(int groupNum) { 52 if (groupNum > mNumGroups) { 53 throw new IllegalArgumentException("groupNum > " + mNumGroups); 54 } 55 return (Button) mLinearLayout.getChildAt(2*groupNum); 56 } 57 58 @Override onCreate(Bundle icicle)59 protected void onCreate(Bundle icicle) { 60 super.onCreate(icicle); 61 setContentView(R.layout.scrollview_linear_layout); 62 63 64 // estimated ratio to get enough buttons so a couple are off screen 65 int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); 66 mNumGroups = screenHeight / 30; 67 68 mScrollView = findViewById(R.id.scrollView); 69 mLinearLayout = findViewById(R.id.layout); 70 71 LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( 72 LinearLayout.LayoutParams.MATCH_PARENT, 73 LinearLayout.LayoutParams.WRAP_CONTENT 74 ); 75 76 for (int i = 0; i < mNumGroups; i++) { 77 // want button to be first and last 78 if (i > 0) { 79 TextView textView = new TextView(this); 80 textView.setText("Text View " + i); 81 mLinearLayout.addView(textView, p); 82 } 83 84 Button button = new Button(this); 85 button.setText("Button " + (i + 1)); 86 mLinearLayout.addView(button, p); 87 } 88 } 89 90 } 91