Search in sources :

Example 21 with LinearLayout

use of android.widget.LinearLayout in project android_frameworks_base by ParanoidAndroid.

the class ListItemFactory method horizontalButtonSlots.

/**
     * Create a horizontal linear layout divided into thirds (with some margins
     * separating the thirds), filled with buttons into some slots.
     * @param context The context.
     * @param desiredHeight The height of the LL.
     * @param slots Which slots to fill with buttons.
     * @return The linear layout.
     */
public static View horizontalButtonSlots(Context context, int desiredHeight, Slot... slots) {
    final LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, desiredHeight);
    lp.setMargins(10, 0, 10, 0);
    lp.weight = 0.33f;
    boolean left = false;
    boolean middle = false;
    boolean right = false;
    for (Slot slot : slots) {
        switch(slot) {
            case Left:
                left = true;
                break;
            case Middle:
                middle = true;
                break;
            case Right:
                right = true;
                break;
        }
    }
    if (left) {
        final Button button = new Button(context);
        button.setText("left");
        ll.addView(button, lp);
    } else {
        ll.addView(new View(context), lp);
    }
    if (middle) {
        final Button button = new Button(context);
        button.setText("center");
        ll.addView(button, lp);
    } else {
        ll.addView(new View(context), lp);
    }
    if (right) {
        final Button button = new Button(context);
        button.setText("right");
        ll.addView(button, lp);
    } else {
        ll.addView(new View(context), lp);
    }
    return ll;
}
Also used : Button(android.widget.Button) TextView(android.widget.TextView) View(android.view.View) AbsListView(android.widget.AbsListView) LinearLayout(android.widget.LinearLayout)

Example 22 with LinearLayout

use of android.widget.LinearLayout in project android_frameworks_base by ParanoidAndroid.

the class ListItemFactory method doubleText.

/**
     * Create a text view ready to be a list item.
     *
     * @param position      The position within the list.
     * @param context       The context.
     * @param text          The text of the button
     * @param desiredHeight The desired height of the button
     * @return The created view.
     */
public static View doubleText(int position, Context context, String text, int desiredHeight) {
    final LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    final AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, desiredHeight);
    ll.setLayoutParams(lp);
    ll.setId(position);
    TextView t1 = new TextView(context);
    t1.setHeight(desiredHeight);
    t1.setText(text);
    t1.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    final ViewGroup.LayoutParams lp1 = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
    ll.addView(t1, lp1);
    TextView t2 = new TextView(context);
    t2.setHeight(desiredHeight);
    t2.setText(text);
    t2.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    final ViewGroup.LayoutParams lp2 = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
    ll.addView(t2, lp2);
    ll.setTag("double");
    return ll;
}
Also used : ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 23 with LinearLayout

use of android.widget.LinearLayout in project android_frameworks_base by ParanoidAndroid.

the class ListItemFactory method twoButtonsSeparatedByFiller.

/**
     * Create a view with a button at the top and bottom, with filler in between.
     * The filler is sized to take up any space left over within desiredHeight.
     *
     * @param position      The position within the list.
     * @param context       The context.
     * @param desiredHeight The desired height of the entire view.
     * @return The created view.
     */
public static View twoButtonsSeparatedByFiller(int position, Context context, int desiredHeight) {
    if (desiredHeight < 90) {
        throw new IllegalArgumentException("need at least 90 pixels of height " + "to create the two buttons and leave 10 pixels for the filler");
    }
    final LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.VERTICAL);
    final LinearLayout.LayoutParams buttonLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 50);
    final Button topButton = new Button(context);
    topButton.setLayoutParams(buttonLp);
    topButton.setText("top (position " + position + ")");
    ll.addView(topButton);
    final TextView middleFiller = new TextView(context);
    middleFiller.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, desiredHeight - 100));
    middleFiller.setText("filler");
    ll.addView(middleFiller);
    final Button bottomButton = new Button(context);
    bottomButton.setLayoutParams(buttonLp);
    bottomButton.setText("bottom (position " + position + ")");
    ll.addView(bottomButton);
    ll.setTag("twoButtons");
    return ll;
}
Also used : Button(android.widget.Button) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 24 with LinearLayout

use of android.widget.LinearLayout in project android_frameworks_base by ParanoidAndroid.

the class ListScenario method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // for test stability, turn off title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    mScreenHeight = getWindowManager().getDefaultDisplay().getHeight();
    final Params params = createParams();
    init(params);
    readAndValidateParams(params);
    mListView = createListView();
    mListView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mListView.setDrawSelectorOnTop(false);
    for (int i = 0; i < mHeaderViewCount; i++) {
        TextView header = mHeadersFocusable ? new EditText(this) : new TextView(this);
        header.setText("Header: " + i);
        mListView.addHeaderView(header);
    }
    for (int i = 0; i < mFooterViewCount; i++) {
        TextView header = new TextView(this);
        header.setText("Footer: " + i);
        mListView.addFooterView(header);
    }
    if (params.mConnectAdapter) {
        setAdapter(mListView);
    }
    mListView.setItemsCanFocus(mItemsFocusable);
    if (mStartingSelectionPosition >= 0) {
        mListView.setSelection(mStartingSelectionPosition);
    }
    mListView.setPadding(0, 0, 0, 0);
    mListView.setStackFromBottom(mStackFromBottom);
    mListView.setDivider(null);
    mListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView parent, View v, int position, long id) {
            positionSelected(position);
        }

        public void onNothingSelected(AdapterView parent) {
            nothingSelected();
        }
    });
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int position, long id) {
            positionClicked(position);
        }
    });
    // height for test stability
    if (params.mFadingEdgeScreenSizeFactor != null) {
        mListView.setFadingEdgeLength((int) (params.mFadingEdgeScreenSizeFactor * mScreenHeight));
    } else {
        mListView.setFadingEdgeLength((int) ((64.0 / 480) * mScreenHeight));
    }
    if (mIncludeHeader) {
        mLinearLayout = new LinearLayout(this);
        mHeaderTextView = new TextView(this);
        mHeaderTextView.setText("hi");
        mHeaderTextView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        mLinearLayout.addView(mHeaderTextView);
        mLinearLayout.setOrientation(LinearLayout.VERTICAL);
        mLinearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        mListView.setLayoutParams((new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)));
        mLinearLayout.addView(mListView);
        setContentView(mLinearLayout);
    } else {
        mLinearLayout = new LinearLayout(this);
        mLinearLayout.setOrientation(LinearLayout.VERTICAL);
        mLinearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        mListView.setLayoutParams((new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)));
        mLinearLayout.addView(mListView);
        setContentView(mLinearLayout);
    }
}
Also used : EditText(android.widget.EditText) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout)

Example 25 with LinearLayout

use of android.widget.LinearLayout in project android_frameworks_base by ParanoidAndroid.

the class ScrollViewScenario method onCreate.

@Override
protected void onCreate(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);
}
Also used : ViewGroup(android.view.ViewGroup) LinearLayout(android.widget.LinearLayout)

Aggregations

LinearLayout (android.widget.LinearLayout)1171 View (android.view.View)457 TextView (android.widget.TextView)435 ViewGroup (android.view.ViewGroup)200 ImageView (android.widget.ImageView)189 Button (android.widget.Button)164 ScrollView (android.widget.ScrollView)123 ListView (android.widget.ListView)97 LayoutInflater (android.view.LayoutInflater)86 FrameLayout (android.widget.FrameLayout)85 Context (android.content.Context)74 AdapterView (android.widget.AdapterView)71 EditText (android.widget.EditText)69 Intent (android.content.Intent)58 AbsListView (android.widget.AbsListView)58 LayoutParams (android.widget.LinearLayout.LayoutParams)48 RelativeLayout (android.widget.RelativeLayout)48 Bitmap (android.graphics.Bitmap)45 OnClickListener (android.view.View.OnClickListener)44 Drawable (android.graphics.drawable.Drawable)42