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:org.openmrs.mobile.activities.fragments.FormPageFragment.java

void addSection(Section section, LinearLayout parent) {
    LinearLayout sectionLL = new LinearLayout(getActivity());
    sectionLL.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    //get resources

    Resources r = getActivity().getResources();
    float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
    float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
    float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
    float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

    layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin),
            Math.round(pxBottomMargin));

    parent.addView(sectionLL);// www.  j a  v a 2  s. c o m
    TextView tv = new TextView(getActivity());
    tv.setText(section.getLabel());
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
    sectionLL.addView(tv, layoutParams);

    for (Question question : section.getQuestions()) {
        addQuestion(question, sectionLL);
    }

}

From source file:com.mishiranu.dashchan.content.service.AudioPlayerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = new ContextThemeWrapper(this, Preferences.getThemeResource());
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    float density = ResourceUtils.obtainDensity(this);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
    linearLayout.setPadding(padding, padding, padding, C.API_LOLLIPOP ? (int) (8f * density) : padding);
    textView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    textView.setPadding(0, 0, 0, 0);//w w  w . jav a2s.  c o m
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);
    LinearLayout horizontal = new LinearLayout(context);
    horizontal.setOrientation(LinearLayout.HORIZONTAL);
    horizontal.setGravity(Gravity.CENTER_VERTICAL);
    horizontal.setPadding(0, (int) (16f * density), 0, 0);
    linearLayout.addView(horizontal, LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    seekBar = new SeekBar(context);
    horizontal.addView(seekBar, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    seekBar.setPadding((int) (8f * density), 0, (int) (16f * density), 0);
    seekBar.setOnSeekBarChangeListener(this);
    button = new ImageButton(context);
    horizontal.addView(button, (int) (48f * density), (int) (48f * density));
    button.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.listChoiceBackgroundIndicator, 0));
    setPlayState(false);
    button.setOnClickListener(this);
    alertDialog = new AlertDialog.Builder(context).setView(linearLayout).setOnCancelListener(this)
            .setPositiveButton(R.string.action_stop, this).show();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(AudioPlayerService.ACTION_TOGGLE);
    intentFilter.addAction(AudioPlayerService.ACTION_CANCEL);
    LocalBroadcastManager.getInstance(this).registerReceiver(audioPlayerReceiver, intentFilter);
    bindService(new Intent(this, AudioPlayerService.class), this, 0);
}

From source file:com.github.capone.controller.favorites.FavoritesFragment.java

@Override
public void onClick(View v) {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    final EditText name = new EditText(getActivity());
    name.setHint(R.string.server_name);/*from   w ww  . ja  va 2s  . com*/
    final EditText address = new EditText(getActivity());
    address.setHint(R.string.server_address);
    final EditText publicKey = new EditText(getActivity());
    publicKey.setHint(R.string.public_key);

    LinearLayout layout = new LinearLayout(getActivity());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(name, params);
    layout.addView(address, params);
    layout.addView(publicKey, params);

    new AlertDialog.Builder(getActivity()).setTitle(R.string.title_add_favorite)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    addServer(name.getText().toString(), address.getText().toString(),
                            publicKey.getText().toString());
                }
            }).setView(layout).show();
}

From source file:com.cleanwiz.applock.ui.adapter.AppPagerAdapter.java

private View buildPagerView(final List<CommLockInfo> pData) {

    View pagerView = mInflater.inflate(R.layout.pager_applock_old, null);
    LinearLayout layout_lines = (LinearLayout) pagerView.findViewById(R.id.layout_lines);
    List<LinearLayout> lines = new ArrayList<LinearLayout>();

    for (int i = 0; i < line_num; i++) {
        LinearLayout line = new LinearLayout(mContext);
        line.setOrientation(LinearLayout.HORIZONTAL);
        lines.add(line);//from  ww w  .  j ava 2s . c  o  m
        layout_lines.addView(line);

    }
    int num = 0;
    for (CommLockInfo lockInfo : pData) {
        View appView = buildAppView(lockInfo);
        lines.get(num++ / APP_GRID_COLUMN).addView(appView);
    }

    return pagerView;

}

From source file:com.gandulf.guilib.view.adapter.MultiFragmentPagerAdapter.java

@Override
public Object instantiateItem(View container, int position) {
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }/*from  w  w  w .ja  va  2  s  .c om*/

    LinearLayout v = new LinearLayout(mContext);
    v.setOrientation(LinearLayout.HORIZONTAL);
    v.setWeightSum(getCount(position));

    int startIndex = getStartIndex(position);

    int containerId = 0;
    final int size = getCount(position);
    for (int i = 0; i < size; i++) {

        containerId = startIndex + i;

        String name = makeFragmentName(container.getId(), containerId);
        Fragment fragment = mFragmentManager.findFragmentByTag(name);

        FrameLayout fragmentView = new FrameLayout(mContext);
        LayoutParams layoutParams = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
        fragmentView.setLayoutParams(layoutParams);
        fragmentView.setId(containerId);
        v.addView(fragmentView, i);

        if (fragment != null) {
            Debug.verbose("Attaching item #" + position + ": f=" + fragment + " id:" + containerId);
            mCurTransaction.attach(fragment);
        } else {
            // index is 1 based remove 1 to get a 0-based
            fragment = getItem(position, i);
            if (fragment != null) {
                Debug.verbose("Adding item #" + position + ": f=" + fragment + " id:" + containerId);
                mCurTransaction.add(containerId, fragment, name);
            }
        }
        if (fragment != null && !mCurrentPrimaryItems.contains(fragment)) {
            fragment.setMenuVisibility(false);
            fragment.setUserVisibleHint(false);
        }
    }

    mCurTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    ((ViewPager) container).addView(v, 0);

    return v;
}

From source file:org.telegram.ui.Cells.SessionCell.java

public SessionCell(Context context) {
    super(context);

    if (paint == null) {
        paint = new Paint();
        paint.setColor(ContextCompat.getColor(context, R.color.divider));
        paint.setStrokeWidth(1);/*from ww w  . ja  v a  2 s  .c om*/
    }

    setElevation(AndroidUtilities.dp(2));
    setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setWeightSum(1);
    addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 11, 11, 0));

    nameTextView = new TextView(context);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    nameTextView.setLines(1);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);

    onlineTextView = new TextView(context);
    onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    onlineTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);

    if (LocaleController.isRTL) {
        linearLayout.addView(onlineTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 2, 0, 0));
        linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f,
                Gravity.RIGHT | Gravity.TOP, 10, 0, 0, 0));
    } else {
        linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f,
                Gravity.LEFT | Gravity.TOP, 0, 0, 10, 0));
        linearLayout.addView(onlineTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
                LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 2, 0, 0));
    }

    detailTextView = new TextView(context);
    detailTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    detailTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    detailTextView.setLines(1);
    detailTextView.setMaxLines(1);
    detailTextView.setSingleLine(true);
    detailTextView.setEllipsize(TextUtils.TruncateAt.END);
    detailTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(detailTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 36, 17, 0));

    detailExTextView = new TextView(context);
    detailExTextView.setTextColor(ContextCompat.getColor(context, R.color.secondary_text) /*0xff999999*/);
    detailExTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    detailExTextView.setLines(1);
    detailExTextView.setMaxLines(1);
    detailExTextView.setSingleLine(true);
    detailExTextView.setEllipsize(TextUtils.TruncateAt.END);
    detailExTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(detailExTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 59, 17, 0));
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override//from  w  ww  .java 2s  .  co  m
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}

From source file:com.yanzhenjie.recyclerview.swipe.SwipeMenuView.java

public void createMenu(SwipeMenu swipeMenu, SwipeSwitch swipeSwitch,
        SwipeMenuItemClickListener swipeMenuItemClickListener,
        @SwipeMenuRecyclerView.DirectionMode int direction) {
    removeAllViews();//from  w  ww. ja  v  a 2s.c  o m

    this.mSwipeSwitch = swipeSwitch;
    this.mItemClickListener = swipeMenuItemClickListener;
    this.mDirection = direction;

    List<SwipeMenuItem> items = swipeMenu.getMenuItems();
    for (int i = 0; i < items.size(); i++) {
        SwipeMenuItem item = items.get(i);

        LayoutParams params = new LayoutParams(item.getWidth(), item.getHeight());
        params.weight = item.getWeight();
        LinearLayout parent = new LinearLayout(getContext());
        parent.setId(i);
        parent.setGravity(Gravity.CENTER);
        parent.setOrientation(VERTICAL);
        parent.setLayoutParams(params);
        ViewCompat.setBackground(parent, item.getBackground());
        parent.setOnClickListener(this);
        addView(parent);

        SwipeMenuBridge menuBridge = new SwipeMenuBridge(mDirection, i, mSwipeSwitch, parent);
        parent.setTag(menuBridge);

        if (item.getImage() != null) {
            ImageView iv = createIcon(item);
            menuBridge.mImageView = iv;
            parent.addView(iv);
        }

        if (!TextUtils.isEmpty(item.getText())) {
            TextView tv = createTitle(item);
            menuBridge.mTextView = tv;
            parent.addView(tv);
        }
    }
}

From source file:alexander.martinz.libs.materialpreferences.MaterialEditTextPreference.java

protected AlertDialog createAlertDialog() {
    final Context context = getContext();
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(getTitle());/*  w ww  .ja  v  a2s. c  o m*/

    // create the wrapper layout to apply margins to the edit text
    final LinearLayout wrapper = new LinearLayout(context);
    wrapper.setOrientation(LinearLayout.VERTICAL);
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    final int margin = (int) convertDpToPixels(10);
    layoutParams.setMargins(margin, 0, margin, 0);

    // create the EditText and add it to the wrapper layout
    final EditText editText = new EditText(context);
    editText.setText(mValue);
    wrapper.addView(editText, layoutParams);

    // set our wrapper as view
    builder.setView(wrapper);

    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String value = editText.getText().toString();
            if (TextUtils.equals(value, mValue)) {
                // the value did not change, so lets end here
                return;
            }

            mValue = value;
            final MaterialEditTextPreference preference = MaterialEditTextPreference.this;

            if (mListener != null) {
                if (mListener.onPreferenceChanged(preference, mValue)) {
                    setText(mValue);
                }
            } else {
                setText(mValue);
            }
        }
    });

    return builder.create();
}

From source file:org.musicmod.android.dialog.SleepTimerDialog.java

@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    setContentView(new LinearLayout(this));

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    action = getIntent().getAction();// w ww. j  av a 2 s  .c  om

    mSleepTimerDialog = new AlertDialog.Builder(this).create();
    mSleepTimerDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mRemained = (int) MusicUtils.getSleepTimerRemained() / 1000 / 60;

    LinearLayout mContainer = new LinearLayout(this);
    mContainer.setOrientation(LinearLayout.VERTICAL);
    mContainer.setPadding((int) dm.density * 8, 0, (int) dm.density * 8, 0);
    mTimeView = new TextView(this);
    mContainer.addView(mTimeView);
    mSetTime = new SeekBar(this);
    mSetTime.setMax(120);
    mContainer.addView(mSetTime);

    if (mRemained > 0) {
        mSetTime.setProgress(mRemained);
    } else {
        mSetTime.setProgress(30);
    }

    mSetTime.setOnSeekBarChangeListener(this);

    mProgress = mSetTime.getProgress();
    mTimerTime = mProgress;
    if (mTimerTime >= 1) {
        mPrompt = SleepTimerDialog.this.getResources().getQuantityString(R.plurals.NNNminutes, mTimerTime,
                mTimerTime);
    } else {
        mPrompt = SleepTimerDialog.this.getResources().getString(R.string.disabled);
    }
    mTimeView.setText(mPrompt);

    if (INTENT_SLEEP_TIMER.equals(action)) {
        mSleepTimerDialog.setIcon(android.R.drawable.ic_dialog_info);
        mSleepTimerDialog.setTitle(R.string.set_time);
        mSleepTimerDialog.setView(mContainer);
        mSleepTimerDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.ok),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (mTimerTime >= 1) {
                            long milliseconds = mTimerTime * 60 * 1000;
                            boolean gentle = new PreferencesEditor(getApplicationContext())
                                    .getBooleanPref(KEY_GENTLE_SLEEPTIMER, true);
                            MusicUtils.startSleepTimer(milliseconds, gentle);
                        } else {
                            MusicUtils.stopSleepTimer();
                        }
                        finish();
                    }
                });
        mSleepTimerDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                    }
                });
        mSleepTimerDialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {

                finish();
            }
        });
    } else {
        Toast.makeText(this, R.string.error_bad_parameters, Toast.LENGTH_SHORT).show();
        finish();
    }
}