List of usage examples for android.widget TextView setGravity
public void setGravity(int gravity)
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();//from w w w. j a v a 2 s .co m TextView valueTV = new TextView(context); String title; if (content.has(TITLE)) { title = "Link: " + content.optString(TITLE); } else { title = content.optString(URI); } valueTV.setText(title); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); if (Linkify.addLinks(valueTV, Linkify.ALL)) { if (!allowInteractions) valueTV.setMovementMethod(null); } frame.addView(valueTV); }
From source file:com.darly.dlclent.widget.springindicator.SpringIndicator.java
private void addTabItems() { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f); tabs = new ArrayList<TextView>(); for (int i = 0; i < viewPager.getAdapter().getCount(); i++) { TextView textView = new TextView(getContext()); if (viewPager.getAdapter().getPageTitle(i) != null) { textView.setText(viewPager.getAdapter().getPageTitle(i)); } else {// ww w . j a v a 2s . c o m textView.setText(i + 1 + ""); } textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); textView.setTextColor(getResources().getColor(textColorId)); if (textBgResId != 0) { textView.setBackgroundResource(textBgResId); } textView.setLayoutParams(layoutParams); final int position = i; textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabClickListener == null || tabClickListener.onTabClick(position)) { viewPager.setCurrentItem(position); } } }); tabs.add(textView); tabContainer.addView(textView); } }
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);//from www. j a v a 2 s .c o m container.addView(imageView); container.addView(valueTV); return container; }
From source file:com.google.android.leanbackjank.presenter.GridItemPresenter.java
@Override public ViewHolder onCreateViewHolder(ViewGroup parent) { TextView view = new TextView(parent.getContext()); Resources res = parent.getResources(); int width = res.getDimensionPixelSize(R.dimen.grid_item_width); int height = res.getDimensionPixelSize(R.dimen.grid_item_height); view.setLayoutParams(new ViewGroup.LayoutParams(width, height)); view.setFocusable(true);/*from w ww. ja va2 s. com*/ view.setFocusableInTouchMode(true); view.setBackgroundColor(ResourcesCompat.getColor(parent.getResources(), R.color.jank_yellow, null)); view.setTextColor(Color.WHITE); view.setGravity(Gravity.CENTER); return new ViewHolder(view); }
From source file:ar.com.xpasta.Controls.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);//from w w w . j av a 2s. c o m tab.setGravity(Gravity.CENTER); tab.setSingleLine(); addTab(position, tab); }
From source file:com.aengbee.android.leanback.presenter.GridItemPresenter.java
@Override public ViewHolder onCreateViewHolder(ViewGroup parent) { TextView view = new TextView(parent.getContext()); Resources res = parent.getResources(); int width = res.getDimensionPixelSize(R.dimen.grid_item_width); int height = res.getDimensionPixelSize(R.dimen.grid_item_height); view.setLayoutParams(new ViewGroup.LayoutParams(width, height)); view.setFocusable(true);/* w ww.j a va2 s . com*/ view.setFocusableInTouchMode(true); view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.default_background)); view.setTextColor(Color.WHITE); view.setGravity(Gravity.CENTER); return new ViewHolder(view); }
From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java
private void addTableRow(Row row) { if (row.mLabel.length() > 0 || row.mValue.length() > 0) { int horizontalPadding = (int) (getResources().getDisplayMetrics().density * getResources().getDimension(R.dimen.label_value_padding) + 0.5f); TextView labelView = makeTextView(row.mLabel, getResources().getColor(R.color.dark_text_color), horizontalPadding);//from ww w.j a va 2 s . c om labelView.setGravity(Gravity.RIGHT); TextView valueView = makeTextView(row.mValue, getResources().getColor(R.color.dark_text_color), horizontalPadding); TableRow tableRow = makeTableRow(labelView, valueView); int verticalPadding = (int) (getResources().getDisplayMetrics().density * getResources().getDimension(R.dimen.network_info_vertical_padding) + 0.5f); tableRow.setPadding(0, verticalPadding, 0, verticalPadding); tableRow.setBackgroundColor(getResources().getColor(R.color.background_color_white)); tableRow.setGravity(Gravity.CENTER_HORIZONTAL); mNetworkInfoTableLayout.addView(tableRow); } }
From source file:com.lixiang.weather.support.view.smarttab.SmartTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab * view is not set via {@link #setCustomTabView(int, int)}. *//*from www. j a v a2 s. c om*/ @SuppressLint("NewApi") protected TextView createDefaultTabView(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); // textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { // textView.setBackgroundResource(tabViewBackgroundResId); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the // Theme's // selectableItemBackground to ensure that the View has a pressed // state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); // textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the // Action Bar tab style textView.setAllCaps(tabViewTextAllCaps); } textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
From source file:com.gdpi.app.UpdateManager.java
/** * ?/*w ww . j a v a2 s. c o m*/ */ private void showNoticeDialog() { updateinfo = updateinfo.replaceAll("#", "<br/>"); final TextView text = new TextView(mContext);// text.setGravity(Gravity.LEFT | Gravity.CENTER); text.setTextSize(16); text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (noticeDialog != null) { noticeDialog.dismiss(); noticeDialog = null; } Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(Url)); mContext.startActivity(intent); } }); text.setText(Html.fromHtml("<a href=" + Url + ">" + updateinfo + "</a>")); noticeDialog = AlertUtils.showAlertBtn(mContext, text, "APP???", "?", "??", new View.OnClickListener() { @Override public void onClick(View v) { showDownloadDialog(); noticeDialog.dismiss(); noticeDialog = null; } }, new View.OnClickListener() { @Override public void onClick(View v) { noticeDialog.dismiss(); noticeDialog = null; } }); }
From source file:com.cyntwikip.android.phirelert.FireFeed.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.// www.j a v a 2 s . co m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); /* Edited Part */ //for Fonts //Typeface face = Typeface.createFromAsset(context.getAssets(), "font/Roboto-Light.ttf"); //textView.setTypeface(face); textView.setTypeface(Typeface.SANS_SERIF); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); //textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }