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:Main.java

public static LinearLayout setProgressBarLayout(Activity activity) {

    LinearLayout progressBarLayout = new LinearLayout(activity);
    progressBarLayout.setGravity(Gravity.CENTER);
    ProgressBar spinner = new ProgressBar(activity);
    progressBarLayout.addView(spinner);/*from   w  ww. ja va2s. com*/
    activity.addContentView(progressBarLayout,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    return progressBarLayout;
}

From source file:com.kaedea.frontia.demo.DemoListFragment.java

@SuppressWarnings("ResourceType")
public static View getItemViewLayout(Context context) {
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER_VERTICAL);
    int[] attrs = new int[] { R.attr.selectableItemBackground };
    TypedArray typedArray = context.obtainStyledAttributes(attrs);
    int backgroundResource = typedArray.getResourceId(0, 0);
    linearLayout.setBackgroundResource(backgroundResource);
    typedArray.recycle();// w  ww  .  j ava 2 s .  c  om
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    // Title
    TextView tvTitle = new TextView(context);
    tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16f);
    tvTitle.setMaxLines(1);
    tvTitle.setTextColor(Color.parseColor("#212121"));
    tvTitle.setId(ID_TITLE);
    layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(Utils.dpToPx(context, 20f), Utils.dpToPx(context, 10f), Utils.dpToPx(context, 20f),
            0);
    linearLayout.addView(tvTitle, layoutParams);
    // Sub Title
    TextView tvSubTitle = new TextView(context);
    tvSubTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f);
    tvSubTitle.setMaxLines(2);
    tvSubTitle.setTextColor(Color.parseColor("#757575"));
    tvSubTitle.setId(ID_SUBTITLE);
    layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(Utils.dpToPx(context, 20f), 0, Utils.dpToPx(context, 20f),
            Utils.dpToPx(context, 10f));
    linearLayout.addView(tvSubTitle, layoutParams);
    return linearLayout;
}

From source file:com.nagopy.android.xposed.utilities.ModBrightness.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@XMinSdkVersion(Build.VERSION_CODES.JELLY_BEAN_MR1)
@HandleInitPackageResources(targetPackage = XConst.PKG_SYSTEM_UI, summary = "??")
public static void brightnessDebugger(final String modulePath, final InitPackageResourcesParam resparam,
        final ModBrightnessSettingsGen settings) throws Throwable {
    if (!settings.brightnessDebugger) {
        return;/*from   w  w  w.  ja  v  a 2 s  .co  m*/
    }

    resparam.res.hookLayout(XConst.PKG_SYSTEM_UI, "layout", "super_status_bar", new XC_LayoutInflated() {
        @Override
        public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable {
            LinearLayout parent = (LinearLayout) liparam.view
                    .findViewById(liparam.res.getIdentifier("system_icon_area", "id", XConst.PKG_SYSTEM_UI));

            // ?
            TextView luxTextView = new TextView(parent.getContext());
            luxTextView.setTextSize(8);
            luxTextView.setSingleLine(false);
            luxTextView.setTextColor(Color.WHITE);
            luxTextView.setText("");
            parent.setGravity(Gravity.CENTER_VERTICAL);
            parent.addView(luxTextView, 0);
            AutoBrightnessController autoBrightnessChangedReceiver = new AutoBrightnessController(luxTextView);
            IntentFilter intentFilter = new IntentFilter(
                    AutoBrightnessController.ACTION_AUTO_BRIGHTNESS_CHANGED);
            intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
            parent.getContext().registerReceiver(autoBrightnessChangedReceiver, intentFilter);
        }
    });
}

From source file:com.roy.test.ContentFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);//w ww . j  av a2s  . c  om
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);
    text.setPadding(20, 20, 20, 20);

    LinearLayout layout = maker.addColLayout(false, maker.layFF(0));

    layout.setGravity(Gravity.CENTER);
    layout.addView(text);

    return layout;
}

From source file:com.alibaba.akita.samples.TestFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
        mContent = savedInstanceState.getString(KEY_CONTENT);
    }/*from  www  .j  ava 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(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    layout.setGravity(Gravity.CENTER);
    layout.addView(text);

    return layout;
}

From source file:com.matthewmitchell.wakeifyplus.MinutesSecondsFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    TableRow.LayoutParams twoLP = new TableRow.LayoutParams(0, 0, 0.2f);
    TableRow.LayoutParams threeLP = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT, 0.3f);

    View spacer = new View(activity);
    spacer.setLayoutParams(twoLP);//from   ww w. j a  va2s  .com
    spacer.setVisibility(View.INVISIBLE);

    final NumberPicker minutes = new NumberPicker(activity);
    minutes.setMaxValue(30);
    minutes.setMinValue(0);
    minutes.setValue(defaultMinute);
    minutes.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    LinearLayout minutesLayout = new LinearLayout(activity);
    minutesLayout.addView(minutes);
    minutesLayout.setGravity(Gravity.CENTER);
    minutesLayout.setLayoutParams(threeLP);

    final NumberPicker seconds = new NumberPicker(activity);
    seconds.setMaxValue(59);
    seconds.setMinValue(0);
    seconds.setValue(defaultSecond);
    seconds.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    LinearLayout secondsLayout = new LinearLayout(activity);
    secondsLayout.addView(seconds);
    secondsLayout.setGravity(Gravity.CENTER);
    secondsLayout.setLayoutParams(threeLP);

    LinearLayout layout = new LinearLayout(activity);
    layout.addView(spacer);
    layout.addView(minutesLayout);
    layout.addView(secondsLayout);
    layout.setWeightSum(1.0f);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage("Set Volume Ramping Time").setView(layout)
            .setPositiveButton("Set", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.rampingMinutes = minutes.getValue();
                    activity.rampingSeconds = seconds.getValue();
                    TextView edit = (TextView) activity.findViewById(R.id.volume_ramping);
                    edit.setText(activity.rampingMinutes + "m" + activity.rampingSeconds + "s");
                }

            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();

}

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  w  w . j a  v  a2s . c om

    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:edu.csh.coursebrowser.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    this.setTitle("Settings");
    final SharedPreferences sp = SchoolActivity.sp;
    LinearLayout ll = (LinearLayout) this.findViewById(R.id.settings_layout);
    ll.setGravity(Gravity.CENTER);
    final TextView tv = new TextView(this);
    if (!sp.contains("quarter")) {
        SharedPreferences.Editor e = sp.edit();
        e.putString("quarter", "20122");
        e.commit();// w w w .ja  v  a  2 s.c o m
    }
    tv.setText("Current Quarter: " + sp.getString("quarter", "20122"));
    Button b = new Button(this);
    b.setText("Change Quarter");
    ll.addView(tv);
    ll.addView(b);
    ll.setPadding(10, 10, 10, 10);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder changeQuarter = new AlertDialog.Builder(SettingsActivity.this);
            changeQuarter.setTitle("Change Quarter");
            changeQuarter.setMessage("Select New Quarter");
            final RadioButton ld = new RadioButton(SettingsActivity.this);
            ld.setText("20121");
            ld.setId(1);
            final RadioButton s = new RadioButton(SettingsActivity.this);
            s.setText("20122 (Current)");
            s.setId(2);
            final RadioButton d = new RadioButton(SettingsActivity.this);
            d.setText("20123");
            d.setId(3);
            final RadioGroup rg = new RadioGroup(SettingsActivity.this);
            rg.addView(ld);
            rg.addView(s);
            rg.addView(d);
            changeQuarter.setView(rg);

            changeQuarter.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }

            });
            changeQuarter.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String q;
                    int n = rg.getCheckedRadioButtonId();
                    if (n == 1)
                        q = "20121";
                    else if (n == 2)
                        q = "20122";
                    else
                        q = "20123";
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("quarter", q);
                    edit.commit();
                    SettingsActivity.this.finish();
                }
            });

            changeQuarter.show();
        }

    });

}

From source file:org.openmrs.mobile.activities.fragments.FormPageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.form_page_fragment, container, false);
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    LinearLayout parent = (LinearLayout) rootView.findViewById(R.id.viewholder);
    parent.setGravity(Gravity.CENTER);
    Page page = getPageObject();/*from w w  w.  ja v a 2s.  c o m*/
    List<Section> sectionList = page.getSections();
    for (Section section : sectionList)
        addSection(section, parent);

    return rootView;
}

From source file:com.tweetlanes.android.core.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);
    }//  w  ww  . ja va2  s .  co  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(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    layout.setGravity(Gravity.CENTER);
    layout.addView(text);

    setInitialDownloadState(InitialDownloadState.DOWNLOADED);

    return layout;
}