FileDocCategorySizeDatePackage
ScrollViewButtonsAndLabels.javaAPI DocAndroid 5.1 API2682Thu Mar 12 22:22:12 GMT 2015android.widget.scroll

ScrollViewButtonsAndLabels

public class ScrollViewButtonsAndLabels extends android.app.Activity
Basic scroll view example

Fields Summary
private android.widget.ScrollView
mScrollView
private android.widget.LinearLayout
mLinearLayout
private int
mNumGroups
Constructors Summary
Methods Summary
public android.widget.ButtongetButton(int groupNum)

        if (groupNum > mNumGroups) {
            throw new IllegalArgumentException("groupNum > " + mNumGroups);
        }
        return (Button) mLinearLayout.getChildAt(2*groupNum);
    
public android.widget.LinearLayoutgetLinearLayout()

        return mLinearLayout;
    
public intgetNumButtons()

        return mNumGroups;
    
public android.widget.ScrollViewgetScrollView()



       
        return mScrollView;
    
protected voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        setContentView(R.layout.scrollview_linear_layout);


        // estimated ratio to get enough buttons so a couple are off screen
        int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
        mNumGroups = screenHeight / 30;

        mScrollView = (ScrollView) findViewById(R.id.scrollView);
        mLinearLayout = (LinearLayout) findViewById(R.id.layout);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );

        for (int i = 0; i < mNumGroups; i++) {
            // want button to be first and last
            if (i > 0) {
                TextView textView = new TextView(this);
                textView.setText("Text View " + i);
                mLinearLayout.addView(textView, p);
            }

            Button button = new Button(this);
            button.setText("Button " + (i + 1));
            mLinearLayout.addView(button, p);
        }