Example usage for android.widget LinearLayout setGravity

List of usage examples for android.widget LinearLayout setGravity

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setGravity(int gravity) 

Source Link

Document

Describes how the child views are positioned.

Usage

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from w ww.java2s. c  o m
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.play);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);
    valueTV.setText(asText(content));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);

    container.addView(imageView);
    container.addView(valueTV);
    frame.addView(container);
}

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.j  a va2 s  .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.shafiq.mytwittle.view.PlaceholderPagerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
        mContent = savedInstanceState.getString(KEY_CONTENT);
    }//from  w w w.  j  a v a 2 s . c o  m

    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);
    text.setPadding(20, 20, 20, 20);

    LinearLayout layout = new LinearLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.FILL_PARENT));
    layout.setGravity(Gravity.CENTER);
    layout.addView(text);

    setInitialDownloadState(InitialDownloadState.DOWNLOADED);

    return layout;
}

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);/* ww  w  . j ava2  s  .  c o m*/
    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();
}

From source file:it.unibs.sandroide.lib.beacon.ui.BeaconTagActivity.java

private void renderListViews() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.TOP);

    lvBeacons = new ListView(this);
    lvBeacons.setId(LISTBEACONS_VIEW_ID);
    lvBeacons.setDivider(null);/*from  ww w.ja  va  2  s  .c  om*/
    lvBeacons.setDividerHeight(0);

    lvTags = new ListView(this);
    lvTags.setId(LISTTAGS_VIEW_ID);
    lvTags.setVisibility(View.INVISIBLE);
    lvTags.setDivider(null);
    lvTags.setDividerHeight(0);

    layout.addView(lvBeacons, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT, 1));
    layout.addView(lvTags, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT, 1));

    setContentView(layout);
}

From source file:freed.cam.ui.themesample.cameraui.HorizontalValuesFragment.java

private LinearLayout getNewLayout() {
    LinearLayout linearLayout = new LinearLayout(getContext());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(params);
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
    valuesHolder.addView(linearLayout);/*from  w w w. j  ava 2  s  .c o  m*/
    return linearLayout;
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.ProgressFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    FrameLayout cframe = new FrameLayout(context);
    cframe.setId(INTERNAL_CONTENT_CONTAINER_ID);

    TextView tv = new TextView(context);
    tv.setId(INTERNAL_EMPTY_ID);/*from w w  w  .j  av a  2 s.co m*/
    tv.setGravity(Gravity.CENTER);
    cframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    View contentView = onCreateContentView(inflater, cframe, savedInstanceState);
    cframe.addView(contentView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(cframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:net.abcdroid.devfest12.ui.tablet.MapMultiPaneActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    boolean landscape = (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);

    LinearLayout spacerView = (LinearLayout) findViewById(R.id.map_detail_spacer);
    spacerView.setOrientation(landscape ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
    spacerView.setGravity(landscape ? Gravity.RIGHT : Gravity.BOTTOM);

    View popupView = findViewById(R.id.map_detail_popup);
    LinearLayout.LayoutParams popupLayoutParams = (LinearLayout.LayoutParams) popupView.getLayoutParams();
    popupLayoutParams.width = landscape ? 0 : ViewGroup.LayoutParams.MATCH_PARENT;
    popupLayoutParams.height = landscape ? ViewGroup.LayoutParams.MATCH_PARENT : 0;
    popupView.setLayoutParams(popupLayoutParams);

    popupView.requestLayout();// w w  w  . j av a2 s . c  o  m
}

From source file:com.fibrobook.viewpager.custom.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/* ww w . j  a  va  2  s. c  om*/

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    LinearLayout l = new LinearLayout(getActivity());
    params.setMargins(margin, margin, margin, margin);
    l.setLayoutParams(params);
    l.setGravity(Gravity.CENTER);
    l.setBackgroundResource(R.drawable.background_card);

    switch (position) {

    case 0:
        symphtomsView(l);
        break;

    case 1:
        dayView(l);
        break;

    }

    fl.addView(l);
    return fl;
}

From source file:com.kunalkene1797.blackboxkit.fragments.tools.BuildpropFragment.java

private void addKeyDialog(final String key, final String value, final boolean modify) {
    LinearLayout dialogLayout = new LinearLayout(getActivity());
    dialogLayout.setOrientation(LinearLayout.VERTICAL);
    dialogLayout.setGravity(Gravity.CENTER);
    dialogLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText keyEdit = new AppCompatEditText(getActivity());
    keyEdit.setTextColor(getResources().getColor(Utils.DARKTHEME ? R.color.white : R.color.black));

    if (modify)/*from  w w  w.j  a  v a  2 s.  co  m*/
        keyEdit.setText(key.trim());
    else
        keyEdit.setHint(getString(R.string.key));

    final AppCompatEditText valueEdit = new AppCompatEditText(getActivity());
    valueEdit.setTextColor(getResources().getColor(Utils.DARKTHEME ? R.color.white : R.color.black));

    if (modify)
        valueEdit.setText(value.trim());
    else
        valueEdit.setHint(getString(R.string.value));

    dialogLayout.addView(keyEdit);
    dialogLayout.addView(valueEdit);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(dialogLayout)
            .setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (modify)
                        overwrite(key.trim(), value.trim(), keyEdit.getText().toString().trim(),
                                valueEdit.getText().toString().trim());
                    else
                        add(keyEdit.getText().toString().trim(), valueEdit.getText().toString().trim());
                }
            }).show();
}