Example usage for android.widget LinearLayout setOrientation

List of usage examples for android.widget LinearLayout setOrientation

Introduction

In this page you can find the example usage for android.widget LinearLayout setOrientation.

Prototype

public void setOrientation(@OrientationMode int orientation) 

Source Link

Document

Should the layout be a column or a row.

Usage

From source file:com.cssweb.android.quote.QuoteDetail.java

/**
 * ???//www.  j  a va  2  s .  co m
 */
private void initLoading() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    ProgressBar progressBar = new ProgressBar(this);
    progressBar.setPadding(0, 0, 15, 0);
    LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.FILL_PARENT);
    layout.addView(progressBar, layoutParams);
    TextView textView = new TextView(this);
    textView.setText(getResources().getText(R.string.cjmx_loading));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    layout.addView(textView, layoutParams2);
    layout.setGravity(Gravity.CENTER);
    loadingLayout = new LinearLayout(this);
    loadingLayout.addView(layout, layoutParams);
    loadingLayout.setGravity(Gravity.CENTER);
    table_1.addView(loadingLayout, 0);
}

From source file:com.ai.eve.lenovo.widget.FragmentTabHost.java

private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);//from w  w  w .ja  v a 2s.  c  om
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}

From source file:com.example.team04adventure.Controller.OnlineStoryList.java

/**
 * Starts a dialog box which allows the user to create a new story.
 * /* ww w.j a v a2s. c om*/
 * @param view
 *            the current view.
 */
public void addStory(View view) {
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    LinearLayout lila1 = new LinearLayout(this);
    lila1.setOrientation(1);
    final EditText titleinput = new EditText(this);
    final EditText bodyinput = new EditText(this);
    titleinput.setHint("Enter the Title here.");
    bodyinput.setHint("Enter a Synopsis here.");
    lila1.addView(titleinput);
    lila1.addView(bodyinput);
    adb.setView(lila1);

    adb.setTitle("New Story");

    adb.setNegativeButton("Create", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Story story = new Story();
            story.setTitle(titleinput.getText().toString());
            Random rg = new Random();
            int rint = rg.nextInt(100);
            story.setSynopsis(bodyinput.getText().toString());
            story.setId(story.getTitle().replace(" ", "") + rint);
            story.setAuthor(MainActivity.username);
            story.setVersion(1);

            StorageManager sm = new StorageManager(getBaseContext());

            sm.addStory(story);

            Intent intent = new Intent(OnlineStoryList.this, OnlineStoryList.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(intent);
        }
    });

    adb.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {

            return;
        }
    });

    adb.show();

}

From source file:org.mdc.chess.SeekBarPreference.java

@Override
protected View onCreateView(ViewGroup parent) {
    TextView name = new TextView(getContext());
    name.setText(getTitle());/*from  ww  w  . ja v  a2s  .  c  o m*/
    //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
    TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large);
    name.setGravity(Gravity.START);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.START;
    lp.weight = 1.0f;
    name.setLayoutParams(lp);

    currValBox = new TextView(getContext());
    currValBox.setTextSize(12);
    currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
    currValBox.setPadding(2, 5, 0, 0);
    currValBox.setText(valToString());
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    currValBox.setLayoutParams(lp);

    LinearLayout row1 = new LinearLayout(getContext());
    row1.setOrientation(LinearLayout.HORIZONTAL);
    row1.addView(name);
    row1.addView(currValBox);

    final SeekBar bar = new SeekBar(getContext());
    bar.setMax(maxValue);
    bar.setProgress(currVal);
    bar.setOnSeekBarChangeListener(this);
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.END;
    bar.setLayoutParams(lp);

    CharSequence summaryCharSeq = getSummary();
    boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
    TextView summary = null;
    if (haveSummary) {
        summary = new TextView(getContext());
        summary.setText(getSummary());
        //            summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
        summary.setGravity(Gravity.START);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.START;
        lp.weight = 1.0f;
        summary.setLayoutParams(lp);
    }

    LinearLayout layout = new LinearLayout(getContext());
    layout.setPadding(25, 5, 25, 5);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(row1);
    layout.addView(bar);
    if (summary != null) {
        layout.addView(summary);
    }
    layout.setId(android.R.id.widget_frame);

    currValBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
            builder.setView(content);
            String title = "";
            String key = getKey();
            if (key.equals("strength")) {
                title = getContext().getString(R.string.edit_strength);
            } else if (key.equals("bookRandom")) {
                title = getContext().getString(R.string.edit_randomization);
            }
            builder.setTitle(title);
            final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number);
            valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
            final Runnable selectValue = new Runnable() {
                public void run() {
                    try {
                        String txt = valueView.getText().toString();
                        int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
                        if (value < 0)
                            value = 0;
                        if (value > maxValue)
                            value = maxValue;
                        onProgressChanged(bar, value, false);
                    } catch (NumberFormatException ignored) {

                    }
                }
            };
            valueView.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        selectValue.run();
                        return true;
                    }
                    return false;
                }
            });
            builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    selectValue.run();
                }
            });
            builder.setNegativeButton("Cancel", null);

            builder.create().show();
        }
    });

    return layout;
}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java

@Test
public void test_dynamic_layout() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS", new Locale("en", "AU"));
    RecordCategory recordCategory = new RecordCategory();
    Date created = sdf.parse("2014-02-05 18:45:46.145000");
    Date modified = sdf.parse("2014-02-12 11:55:23.121000");
    recordCategory.setCreated(created);/*from www .  j av  a2  s.co m*/
    recordCategory.setModified(modified);
    recordCategory.setCreator("admin");
    recordCategory.setDescription("Information Technology");
    recordCategory.setIdentifier("2014-1391586274589");
    FieldDescriptor descriptionField = new FieldDescriptor();
    descriptionField.setOrder(1);
    descriptionField.setName("description");
    descriptionField.setTitle("Description");
    FieldDescriptor createdField = new FieldDescriptor();
    createdField.setOrder(2);
    createdField.setName("created");
    createdField.setTitle("Created");
    FieldDescriptor creatorField = new FieldDescriptor();
    creatorField.setOrder(3);
    creatorField.setName("creator");
    creatorField.setTitle("Creator");
    FieldDescriptor modifiedField = new FieldDescriptor();
    modifiedField.setOrder(4);
    modifiedField.setName("modified");
    modifiedField.setTitle("Modified");
    FieldDescriptor modifier = new FieldDescriptor();
    modifier.setOrder(5);
    modifier.setName("modifier");
    modifier.setTitle("Modifier");
    FieldDescriptor identifierField = new FieldDescriptor();
    identifierField.setOrder(6);
    identifierField.setName("identifier");
    identifierField.setTitle("Identifier");
    Set<FieldDescriptor> fieldSet = new TreeSet<FieldDescriptor>();
    fieldSet.add(descriptionField);
    fieldSet.add(createdField);
    fieldSet.add(creatorField);
    fieldSet.add(modifiedField);
    fieldSet.add(modifier);
    fieldSet.add(identifierField);
    @SuppressWarnings("unchecked")
    Map<String, Object> valueMap = PropertyUtils.describe(recordCategory);
    titleSearchResultsActivity = (TitleSearchResultsActivity) controller.create().get();
    LinearLayout dynamicLayout = new LinearLayout(titleSearchResultsActivity);
    dynamicLayout.setOrientation(LinearLayout.VERTICAL);
    int layoutHeight = LinearLayout.LayoutParams.MATCH_PARENT;
    int layoutWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
    for (FieldDescriptor descriptor : fieldSet) {
        Object value = valueMap.get(descriptor.getName());
        if (value == null)
            continue;
        TextView titleView = new TextView(titleSearchResultsActivity);
        titleView.setText(descriptor.getTitle());
        TextView valueView = new TextView(titleSearchResultsActivity);
        valueView.setText(value.toString());
        LinearLayout fieldLayout = new LinearLayout(titleSearchResultsActivity);
        fieldLayout.setOrientation(LinearLayout.HORIZONTAL);
        fieldLayout.addView(titleView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight));
        fieldLayout.addView(valueView, new LinearLayout.LayoutParams(layoutWidth, layoutHeight));
    }
}

From source file:co.ldln.android.ObjectCreateFragment.java

@Override
public void onReadSchemaResult(final Schema schema) {
    mTextFields = new ArrayList<EditText>();

    // Create the form based on the schema fields
    List<SchemaField> fieldList = new ArrayList<SchemaField>();
    fieldList.addAll(schema.getFields(mActivity));
    Collections.sort(fieldList);/*from w ww . j  a  v a2s.c  o m*/
    for (SchemaField field : fieldList) {
        String type = field.getType();
        String label = field.getLabel();

        // Create a linear layout to hold the field
        LinearLayout ll = new LinearLayout(mActivity);
        LayoutParams llParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        ll.setLayoutParams(llParams);
        ll.setOrientation(LinearLayout.HORIZONTAL);

        // TODO: different UI for different field types

        // Default to EditText
        EditText et = new EditText(mActivity);
        LayoutParams etParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        et.setLayoutParams(etParams);
        et.setHint(label);
        if (type.equals("map_location"))
            et.setText(mMapLocation);
        ll.addView(et);
        mTextFields.add(et);

        mFormHolder.addView(ll);
    }

    // Add submit button
    Button b = new Button(mActivity);
    LayoutParams bParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    b.setText("Save");
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String kvPairs = "";
                JSONObject kvPairsJsonObject = new JSONObject();
                for (EditText et : mTextFields) {
                    String key = et.getHint().toString();
                    String value = et.getText().toString();
                    kvPairsJsonObject.put(key, value);
                }
                kvPairs = kvPairsJsonObject.toString();

                LDLN.saveSyncableObject(mActivity, ObjectCreateFragment.this, schema.getKey(), kvPairs);
            } catch (JSONException e) {
                e.printStackTrace();
                onSaveSyncableObjectResult(false);
            }
        }
    });
    mFormHolder.addView(b);

    Toast.makeText(mActivity,
            "This is a form that's dynamically generated from a syncable object schema. It will soon have handling for dynamic form elements (photo, latlon picker, etc).",
            Toast.LENGTH_LONG).show();
}

From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    Activity activity = getActivity();//from  ww  w.ja  va  2s . c o  m
    switch (item.getItemId()) {
    case R.id.action_refresh:
        urls = new ArrayList<String>();
        imageAdapter.notifyDataSetChanged();
        getImages();
        return true;
    case R.id.action_new:
        final EditText newTitle = new EditText(activity);
        newTitle.setSingleLine();
        newTitle.setHint(R.string.hint_album_title);
        final EditText newDescription = new EditText(activity);
        newDescription.setHint(R.string.body_hint_description);
        LinearLayout linearLayout = new LinearLayout(activity);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(newTitle);
        linearLayout.addView(newDescription);
        new AlertDialog.Builder(activity).setTitle(R.string.dialog_new_album_title).setView(linearLayout)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        NewAlbumAsync messagingAsync = new NewAlbumAsync(newTitle.getText().toString(),
                                newDescription.getText().toString(),
                                ((ImgurHoloActivity) getActivity()).getApiCall(), null, null);
                        messagingAsync.execute();
                    }
                }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:android.support.v13.app.FragmentTabHost.java

private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();/* www .j a va 2s.c om*/

    super.setOnTabChangedListener(this);

    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}

From source file:com.scxrh.amb.widget.FragmentTabHostState.java

private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);//w  w w .j a v  a 2  s .c o m
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));
        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));
        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}

From source file:com.woodblockwithoutco.quickcontroldock.ui.ControlService.java

public void attachTemporaryView(Drawable icon, String appName) {
    LinearLayout l = new LinearLayout(getApplicationContext());
    l.setGravity(Gravity.CENTER_VERTICAL);
    l.setOrientation(LinearLayout.HORIZONTAL);
    l.setPadding(NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX,
            NOTIFICATION_TOAST_PADDING_PX);

    l.setBackgroundResource(R.drawable.notification_toast_bg);

    TextView tv = new TextView(getApplicationContext());
    tv.setGravity(Gravity.CENTER);//from   w ww.j  a v  a 2  s. com
    tv.setCompoundDrawablePadding(COMPOUND_DRAWABLE_PADDING_PX);
    tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);

    String notificationText = getString(R.string.notification_from) + "\n" + appName;
    tv.setText(notificationText);
    tv.setTextColor(COLOR_WHITE);

    l.addView(tv);

    Toast toast = new Toast(getApplicationContext());
    toast.setView(l);
    toast.show();
}