FileDocCategorySizeDatePackage
ScrollViewScenario.javaAPI DocAndroid 5.1 API9352Thu Mar 12 22:22:12 GMT 2015android.util

ScrollViewScenario

public abstract class ScrollViewScenario extends android.app.Activity
Utility base class for creating scroll view scenarios, allowing you to add a series of different kinds of views arranged vertically, taking up a specified amount of the screen height.

Fields Summary
private android.widget.LinearLayout
mLinearLayout
Holds content of scroll view
private android.widget.ScrollView
mScrollView
The actual scroll view
Constructors Summary
Methods Summary
protected android.widget.ScrollViewcreateScrollView()
Hook for changing how scroll view's are created.

        return new ScrollView(this);
    
public TgetContentChildAt(int index)
Get the child contained within the vertical linear layout of the scroll view.

param
index The index within the linear layout.
return
the child within the vertical linear layout of the scroll view at the specified index.

        return (T) mLinearLayout.getChildAt(index);
    
public android.widget.LinearLayoutgetLinearLayout()

        return mLinearLayout;
    
public android.widget.ScrollViewgetScrollView()

        return mScrollView;
    
protected abstract voidinit(android.util.ScrollViewScenario$Params params)
Override this and initialized the views in the scroll view.

param
params Used to configure the contents of the scroll view.

protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        // for test stability, turn off title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        int screenHeight = getWindowManager().getDefaultDisplay().getHeight()
                - 25;
        mLinearLayout = new LinearLayout(this);
        mLinearLayout.setOrientation(LinearLayout.VERTICAL);

        // initialize params
        final Params params = new Params();
        init(params);

        // create views specified by params
        for (ViewFactory viewFactory : params.mViewFactories) {
            int height = ViewGroup.LayoutParams.WRAP_CONTENT;
            if (viewFactory.getHeightRatio() >= 0) {
                height = (int) (viewFactory.getHeightRatio() * screenHeight);
            }
            final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, height);
            mLinearLayout.addView(viewFactory.create(this), lp);
        }

        mScrollView = createScrollView();
        mScrollView.setPadding(0, params.mTopPadding, 0, params.mBottomPadding);
        mScrollView.addView(mLinearLayout, new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        // no animation to speed up tests
        mScrollView.setSmoothScrollingEnabled(false);

        setContentView(mScrollView);