List of usage examples for android.widget LinearLayout setGravity
@android.view.RemotableViewMethod public void setGravity(int gravity)
From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java
private void addIconAndTextTab(int position, int resId, String title) { LinearLayout tab = new LinearLayout(getContext()); tab.setGravity(Gravity.CENTER); TextView text = new TextView(getContext()); text.setText(title);/*from w w w . jav a 2 s . co m*/ text.setTextColor(Color.WHITE); text.setGravity(Gravity.CENTER); text.setSingleLine(); ImageView img = new ImageView(getContext()); img.setImageBitmap(iProvider.getBitmap(resId)); tab.addView(img); tab.addView(text); text.setPadding(10, 0, 0, 0); text.setTag("TEXT"); addTab(position, tab); }
From source file:org.borderstone.tagtags.TTStartActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setTheme(R.style.AppTheme); this.setContentView(R.layout.activity_start); Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar); //toolbar.inflateMenu(R.menu.menu_start); toolbar.setTitle("TagTags"); toolbar.setVisibility(View.VISIBLE); TTStartActivity.me = getApplicationContext(); protocol.setAction("android.intent.action.PROTOCOL"); settings.setAction("android.intent.action.SETTINGS"); Constants.init(new File(this.getFilesDir(), "bsettings.txt"), this.getApplicationContext()); Constants.fileListener = this; /*Load variables that are stored in a text file keeping version info and info about third party resources here, for easy editing*/ try {//from w w w . j a v a 2 s . c o m BufferedReader reader = new BufferedReader( new InputStreamReader(this.getResources().openRawResource(R.raw.appinfo))); String line = reader.readLine(); String[] t; while (line != null) { t = line.split(":"); if (line.startsWith("#thirdparty:")) thirdparty += t[1] + "\n"; else if (line.startsWith("#recentchanges:")) recentchanges += "-- " + t[1] + "\n"; line = reader.readLine(); } //just to remove the final new line. if (!thirdparty.equals("")) thirdparty = thirdparty.substring(0, thirdparty.length() - 1); if (!recentchanges.equals("")) recentchanges = recentchanges.substring(0, recentchanges.length() - 1); } catch (Exception ignored) { } //Most of the code below is purely for aesthetics! txtPhilosophy = new BTitleLabel(this); txtPhilosophy.setTypeface(Typeface.DEFAULT_BOLD); txtPhilosophy.setLayoutParams(Constants.defaultParams); txtPhilosophy.setOnClickListener(this); txtPhilosophy.setTextColor(Color.BLACK); txtVersion = new BStandardLabel(this); txtVersion.setText("Recent changes:\n" + recentchanges); txtVersion.setLayoutParams(Constants.defaultParams); txtVersion.setTextColor(Color.BLACK); try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); toolbar.setSubtitle("v. " + pInfo.versionName); } catch (PackageManager.NameNotFoundException ignored) { } toolbar.setNavigationIcon(R.drawable.drawer); ImageView slu = new ImageView(this); ImageView sites = new ImageView(this); slu.setImageResource(R.drawable.slulogo); sites.setImageResource(R.drawable.sites); LinearLayout llLogos = new LinearLayout(this); llLogos.setOrientation(LinearLayout.HORIZONTAL); llLogos.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); llLogos.addView(slu); llLogos.addView(sites); setPhiloText(); LinearLayout back = (LinearLayout) this.findViewById(R.id.back); back.setOrientation(LinearLayout.VERTICAL); txtPhilosophy.setLayoutParams(Constants.defaultParams); txtPhilosophy.setBackgroundResource(R.drawable.border); txtVersion.setLayoutParams(Constants.defaultParams); txtVersion.setBackgroundResource(R.drawable.border_recurring); back.addView(txtPhilosophy); back.addView(txtVersion); back.addView(llLogos); lblSettings = new BButton(this); lblDownload = new BButton(this); lblDownload.setIcon(R.drawable.download); lblSettings.setIcon(R.drawable.settings); lblSettings.setText("Settings"); lblDownload.setText("Download from server"); lblSettings.setOnClickListener(this); lblDownload.setOnClickListener(this); if (!checkPermissions()) { final Intent intro = new Intent(); intro.setAction("android.intent.action.INTRO"); this.startActivity(intro); } BTitleLabel lblProperties = new BTitleLabel(this); BTitleLabel lblLocal = new BTitleLabel(this); fileNavView = new BFileNavView(this, this); lblProperties.setTextSize(Constants.fontSize + 2); lblLocal.setTextSize(Constants.fontSize + 2); lblProperties.setText("PROPERTIES"); lblProperties.setTextColor(Color.WHITE); lblProperties.setGravity(Gravity.CENTER); lblLocal.setText("LOCAL FILES"); lblLocal.setTextColor(Color.WHITE); lblLocal.setGravity(Gravity.CENTER); final DrawerLayout drawerLayout = (DrawerLayout) this.findViewById(R.id.startDrawerLayout); final LinearLayout drawer = (LinearLayout) this.findViewById(R.id.drawer); drawer.setClickable(false); drawer.bringToFront(); drawer.addView(lblProperties); drawer.addView(lblDownload); drawer.addView(lblSettings); drawer.addView(lblLocal); drawer.addView(fileNavView); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!drawerLayout.isDrawerOpen(Gravity.LEFT)) drawerLayout.openDrawer(Gravity.LEFT); else drawerLayout.closeDrawer(Gravity.LEFT); } }); }
From source file:mobisocial.musubi.objects.FileObj.java
@Override public View createView(Context context, ViewGroup frame) { LinearLayout container = new LinearLayout(context); container.setLayoutParams(CommonLayouts.FULL_WIDTH); container.setOrientation(LinearLayout.HORIZONTAL); container.setGravity(Gravity.CENTER); ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView valueTV = new TextView(context); 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);/*w w w. j a v a2 s.c o m*/ container.addView(imageView); container.addView(valueTV); return container; }
From source file:org.openmrs.mobile.activities.fragments.FormPageFragment.java
void addQuestion(Question question, LinearLayout parent) { if (question.getQuestionOptions().getRendering().equals("group")) { LinearLayout questionLL = new LinearLayout(getActivity()); questionLL.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); questionLL.setGravity(Gravity.CENTER); parent.addView(questionLL);//from ww w .ja va2s. c om 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)); TextView tv = new TextView(getActivity()); tv.setText(question.getLabel()); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary)); questionLL.addView(tv, layoutParams); for (Question subquestion : question.getQuestions()) { addQuestion(subquestion, questionLL); } } if (question.getQuestionOptions().getRendering().equals("number")) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 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)); RangeEditText ed = new RangeEditText(getActivity()); ed.setName(question.getLabel()); if (question.getQuestionOptions().getMax() != null) { ed.setHint(question.getLabel() + " [" + question.getQuestionOptions().getMin() + "-" + question.getQuestionOptions().getMax() + "]"); ed.setUpperlimit(Double.parseDouble(question.getQuestionOptions().getMax())); ed.setLowerlimit(Double.parseDouble(question.getQuestionOptions().getMin())); } else { ed.setHint(question.getLabel()); ed.setLowerlimit(-1.0); ed.setUpperlimit(-1.0); } ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ed.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); int id = InputField.generateViewId(); InputField field = new InputField(); ed.setId(id); field.setId(id); field.setConcept(question.getQuestionOptions().getConcept()); inputFields.add(field); parent.addView(ed, layoutParams); } }
From source file:com.lgh.tool.myview.PagerSlidingTabStrip.java
/** * ?//w ww. ja va 2 s. c o m */ private ViewGroup getTabsLayout() { if (tabsLayout == null) { if (getChildCount() > 0) { tabsLayout = (ViewGroup) getChildAt(0); } else { removeAllViews(); LinearLayout tabsLayout = new LinearLayout(getContext()); tabsLayout.setGravity(Gravity.CENTER_VERTICAL); this.tabsLayout = tabsLayout; addView(tabsLayout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); } } return tabsLayout; }
From source file:org.onebusaway.android.ui.ListFragment.java
/** * Provide default implementation to return a simple list view. Subclasses * can override to replace with their own layout. If doing so, the * returned view hierarchy <em>must</em> have a ListView whose id * is {@link android.R.id#list android.R.id.list} and can optionally * have a sibling view id {@link android.R.id#empty android.R.id.empty} * that is to be shown when the list is empty. * * <p>If you are overriding this method with your own custom content, * consider including the standard layout {@link android.R.layout#list_content} * in your layout file, so that you continue to retain all of the standard * behavior of ListFragment. In particular, this is currently the only * way to have the built-in indeterminant progress state be shown. *///from w ww .ja v a 2s. com @Override @SuppressWarnings("deprecation") 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(R.id.loading); 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 lframe = new FrameLayout(context); lframe.setId(R.id.listContainer); TextView tv = new TextView(getActivity()); tv.setId(R.id.internalEmpty); tv.setGravity(Gravity.CENTER); lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); ListView lv = new ListView(getActivity()); lv.setId(android.R.id.list); lv.setDrawSelectorOnTop(false); lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); root.addView(lframe, 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:edu.byu.scriptures.controller.fragment.RestartableRecyclerFragment.java
/** * Provide default implementation to return a simple list view. Subclasses * can override to replace with their own layout. If doing so, the * returned view hierarchy <em>must</em> have a ListView whose id * is {@link android.R.id#list android.R.id.list} and can optionally * have a sibling view id {@link android.R.id#empty android.R.id.empty} * that is to be shown when the list is empty. * * <p>If you are overriding this method with your own custom content, * consider including the standard layout {@link android.R.layout#list_content} * in your layout file, so that you continue to retain all of the standard * behavior of ListFragment. In particular, this is currently the only * way to have the built-in indeterminant progress state be shown. *///from www . java 2 s .com @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.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ FrameLayout lframe = new FrameLayout(context); lframe.setId(INTERNAL_LIST_CONTAINER_ID); TextView tv = new TextView(getActivity()); tv.setId(INTERNAL_EMPTY_ID); tv.setGravity(Gravity.CENTER); tv.setTextSize(18); int padding = ((MainActivity) getActivity()).getMetricsManager().dpToRawPixels(20); tv.setPadding(padding, 0, padding, 0); tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_normal)); lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); RecyclerView recyclerView = new RecyclerView(getActivity()); recyclerView.setId(android.R.id.list); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); // lv.setDrawSelectorOnTop(false); lframe.addView(recyclerView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return root; }
From source file:com.pikachu.emoji.widget.EmojiView.java
/** * </br>// w w w. jav a 2 s. c o m * * @return */ private ViewGroup createPointLinearlayout() { LinearLayout pointContainerLayout = new LinearLayout(getContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); pointContainerLayout.setLayoutParams(params); pointContainerLayout.setOrientation(LinearLayout.HORIZONTAL); pointContainerLayout.setGravity(Gravity.CENTER); params.gravity = Gravity.CENTER; params.topMargin = CommonUtils.dp2px(getContext(), 15); params.bottomMargin = CommonUtils.dp2px(getContext(), 15); return pointContainerLayout; }
From source file:org.yasik.android.app.GridFragment.java
/** * Provide default implementation to return a simple grid view. Subclasses can * override to replace with their own layout. If doing so, the returned view * hierarchy <em>must</em> have a GridView whose id is * {@link android.R.id#list android.R.id.list} and can optionally have a * sibling view id {@link android.R.id#empty android.R.id.empty} that is to be * shown when the list is empty./*from ww w . j a va 2 s.c o m*/ * * <p>If you are overriding this method with your own custom content, consider * including the standard layout {@link android.R.layout#list_content} in your * layout file, so that you continue to retain all of the standard behavior of * GridFragment. In particular, this is currently the only way to have the * built-in indeterminant progress state be shown. */ @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.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); FrameLayout lframe = new FrameLayout(context); lframe.setId(INTERNAL_LIST_CONTAINER_ID); TextView tv = new TextView(getActivity()); tv.setId(INTERNAL_EMPTY_ID); tv.setGravity(Gravity.CENTER); lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); GridView lv = new GridView(getActivity()); lv.setId(android.R.id.list); lv.setDrawSelectorOnTop(false); lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return root; }
From source file:org.mariotaku.twidere.fragment.BasePullToRefreshListFragment.java
/** * Provide default implementation to return a simple list view. Subclasses * can override to replace with their own layout. If doing so, the returned * view hierarchy <em>must</em> have a ListView whose id is * {@link android.R.id#list android.R.id.list} and can optionally have a * sibling view id {@link android.R.id#empty android.R.id.empty} that is to * be shown when the list is empty.//from ww w . j a va 2s . c om * * <p> * If you are overriding this method with your own custom content, consider * including the standard layout {@link android.R.layout#list_content} in * your layout file, so that you continue to retain all of the standard * behavior of ListFragment. In particular, this is currently the only way * to have the built-in indeterminant progress state be shown. */ @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final Context context = getActivity(); final FrameLayout root = new FrameLayout(context); // ------------------------------------------------------------------ final LinearLayout pframe = new LinearLayout(context); pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID); pframe.setOrientation(LinearLayout.VERTICAL); pframe.setVisibility(View.GONE); pframe.setGravity(Gravity.CENTER); final ProgressBar progress = new HoloProgressBar(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.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ final FrameLayout lframe = new FrameLayout(context); lframe.setId(INTERNAL_LIST_CONTAINER_ID); final TextView tv = new TextView(getActivity()); tv.setId(INTERNAL_EMPTY_ID); tv.setGravity(Gravity.CENTER); lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); final PullToRefreshListView plv = new PullToRefreshListView(context); plv.setOnRefreshListener(this); plv.setShowIndicator(false); plv.setOnPullEventListener(new AccessibilityPullEventListener<ListView>(context)); plv.setPullToRefreshOverScrollEnabled(false); mPullToRefreshListView = plv; final ListView lv = plv.getRefreshableView(); lv.setId(android.R.id.list); lv.setDrawSelectorOnTop(false); // ViewCompat.setOverScrollMode(lv, ViewCompat.OVER_SCROLL_NEVER); lframe.addView(plv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return root; }