2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.widget.scroll;
19 import com.android.frameworks.coretests.R;
21 import android.app.Activity;
22 import android.os.Bundle;
23 import android.widget.LinearLayout;
24 import android.widget.ScrollView;
25 import android.widget.TextView;
26 import android.widget.Button;
30 * Basic scroll view example
32 public class ScrollViewButtonsAndLabels extends Activity {
34 private ScrollView mScrollView;
35 private LinearLayout mLinearLayout;
37 private int mNumGroups = 10;
40 public ScrollView getScrollView() {
44 public LinearLayout getLinearLayout() {
48 public int getNumButtons() {
52 public Button getButton(int groupNum) {
53 if (groupNum > mNumGroups) {
54 throw new IllegalArgumentException("groupNum > " + mNumGroups);
56 return (Button) mLinearLayout.getChildAt(2*groupNum);
60 protected void onCreate(Bundle icicle) {
61 super.onCreate(icicle);
62 setContentView(R.layout.scrollview_linear_layout);
65 // estimated ratio to get enough buttons so a couple are off screen
66 int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
67 mNumGroups = screenHeight / 30;
69 mScrollView = (ScrollView) findViewById(R.id.scrollView);
70 mLinearLayout = (LinearLayout) findViewById(R.id.layout);
72 LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
73 LinearLayout.LayoutParams.MATCH_PARENT,
74 LinearLayout.LayoutParams.WRAP_CONTENT
77 for (int i = 0; i < mNumGroups; i++) {
78 // want button to be first and last
80 TextView textView = new TextView(this);
81 textView.setText("Text View " + i);
82 mLinearLayout.addView(textView, p);
85 Button button = new Button(this);
86 button.setText("Button " + (i + 1));
87 mLinearLayout.addView(button, p);