List of usage examples for android.widget TextView setGravity
public void setGravity(int gravity)
From source file:com.fobae.android.views.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)}./* w w w . j a va 2 s. co m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setTextColor(getResources().getColor(R.color.textPrimaryToolbar)); 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; }
From source file:com.cssweb.android.quote.QuoteDetail.java
/** * ???//from w ww .jav a2 s. co m */ private void initLoading() { LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL); ProgressBar progressBar = new ProgressBar(this); progressBar.setPadding(0, 0, 15, 0); LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.addView(progressBar, layoutParams); TextView textView = new TextView(this); textView.setText(getResources().getText(R.string.cjmx_loading)); textView.setGravity(Gravity.CENTER_VERTICAL); layout.addView(textView, layoutParams2); layout.setGravity(Gravity.CENTER); loadingLayout = new LinearLayout(this); loadingLayout.addView(layout, layoutParams); loadingLayout.setGravity(Gravity.CENTER); table_1.addView(loadingLayout, 0); }
From source file:br.edu.ifpb.breath.slidingtabs.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, int)}. *///from www. j a v a 2 s . c om protected View createDefaultTabView(Context context, int type) { if (type == 0) { TextView textView = new TextView(context); 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; } else { ImageView iconView = new ImageView(context); int iconSize = (int) (TAB_VIEW_ICON_SIZE_DIPS * getResources().getDisplayMetrics().density); int padding = (int) (TAB_VIEW_ICON_PADDING_DIPS * getResources().getDisplayMetrics().density); iconView.setLayoutParams(new LinearLayout.LayoutParams(iconSize + padding, iconSize + padding)); iconView.setScaleType(ImageView.ScaleType.FIT_CENTER); iconView.setPadding(padding, padding, padding, padding); return iconView; } }
From source file:at.wada811.android.dialogfragments.sample.alertdialogfragment.AlertDialogFragmentExamplesFragment.java
@Override public DialogFragmentCallback getDialogFragmentCallback() { return new SimpleDialogFragmentCallback() { @Override//from w w w. j a va 2 s.co m public void onShow(DialogFragmentInterface dialog) { String text = "onShow"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public void onCancel(DialogFragmentInterface dialog) { String text = "onCancel"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public void onDismiss(DialogFragmentInterface dialog) { String text = "onDismiss"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public void onClickPositive(DialogFragmentInterface dialog) { String text = "onClickPositive"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public void onClickNeutral(DialogFragmentInterface dialog) { String text = "onClickNeutral"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public void onClickNegative(DialogFragmentInterface dialog) { String text = "onClickNegative"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public boolean onKey(DialogFragmentInterface dialog, int keyCode, KeyEvent event) { String text = "onKey[keyCode: " + keyCode + ", KeyEvent: " + event + "]"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); return false; } @Override public void onItemClick(DialogFragmentInterface dialog, int position) { Bundle extra = dialog.getExtra(); String[] items = extra.getStringArray("items"); String text = "onItemClick[position: " + position + ", item: " + items[position] + "]"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public ListAdapter getAdapter(DialogFragmentInterface dialog) { String[] items = new String[] { AlertDialog.class.getSimpleName(), CharacterPickerDialog.class.getSimpleName(), ProgressDialog.class.getSimpleName(), DatePickerDialog.class.getSimpleName(), TimePickerDialog.class.getSimpleName(), }; Bundle extra = new Bundle(); extra.putStringArray("items", items); dialog.setExtra(extra); return new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items); } @Override public void onSingleChoiceClick(DialogFragmentInterface dialog, int position) { Bundle extra = dialog.getExtra(); String[] items = extra.getStringArray("items"); String text = "onItemClick[position: " + position + ", item: " + items[position] + "]"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public void onMultiChoiceClick(DialogFragmentInterface dialog, int position, boolean isChecked) { Bundle extra = dialog.getExtra(); String[] items = extra.getStringArray("items"); String text = "onItemClick[position: " + position + ", item: " + items[position] + ", isChecked: " + isChecked + "]"; Log.v(dialog.getTag(), text); Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } @Override public View getCustomTitle(DialogFragmentInterface dialog) { TextView titleView = new TextView(getActivity()); titleView.setText(dialog.getTag()); titleView.setPadding(0, 24, 0, 24); titleView.setGravity(Gravity.CENTER); titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); return titleView; } @Override public View getView(DialogFragmentInterface dialog) { ImageView imageView = new ImageView(getActivity()); imageView.setImageResource(R.drawable.ic_launcher); imageView.setPadding(0, 24, 0, 24); return imageView; } }; }
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * SINGLE TITLE ROW//w ww . ja va 2 s . c om * @param att * @param linear * @return */ public LinearLayout getSingleTitleRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setMinimumHeight(30); container_layout .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue)); container_layout.setVerticalGravity(Gravity.CENTER); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); TextView tx = new TextView(context); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value_params); LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); TextView t1 = new TextView(context); t1.setText(att.get("value")); t1.setTextSize(11); t1.setGravity(Gravity.CENTER_HORIZONTAL); t1.setPadding(2, 0, 0, 2); t1.setTextColor(Color.rgb(255, 255, 255)); container_layout.addView(t1, ltext1); linear.addView(container_layout); return linear; }
From source file:com.example.abner.dynamicfragment.view.CustomSlidingTabLayout.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 w w w .j a v a 2 s . c o m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextColor(dTextColor); // mTextSize is sp textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); if (mNeedBold) { textView.setTypeface(Typeface.DEFAULT_BOLD); } 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(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); if (mShouldExpand) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.width = 0; layoutParams.weight = 1; textView.setLayoutParams(layoutParams); } return textView; }
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * DOUBLE TITLE ROW//ww w . j a v a 2 s . c o m * @param att * @param linear * @return */ public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setMinimumHeight(30); container_layout .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue)); container_layout.setVerticalGravity(Gravity.CENTER); container_layout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.3f); TextView tx = new TextView(context); tx.setText(""); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value_params); LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.35f); TextView t1 = new TextView(context); t1.setText(att.get("value1")); t1.setTextSize(11); t1.setGravity(Gravity.CENTER_HORIZONTAL); t1.setPadding(2, 0, 0, 2); t1.setTextColor(Color.rgb(255, 255, 255)); container_layout.addView(t1, ltext1); LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.35f); TextView t2 = new TextView(context); t2.setText(att.get("value2")); t2.setTextSize(11); t2.setGravity(Gravity.CENTER_HORIZONTAL); t2.setPadding(2, 0, 0, 2); t2.setTextColor(Color.rgb(255, 255, 255)); container_layout.addView(t2, ltext2); linear.addView(container_layout); return linear; }
From source file:com.frostwire.android.gui.views.ExpandableListFragment.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 w ww . ja va 2 s .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(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 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.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); ExpandableListView lv = new ExpandableListView(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:com.example.chicharo.clean_ambar.util.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)}.// w ww. j av a2s .c om */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); // textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); 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, //Ripple effect 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(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.androprogrammer.tutorials.customviews.SlidingTabLayout.java
protected TextView createDefaultTextTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); 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); }// ww w. jav a2 s. c o m 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(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); //System.out.println("c " + titleColor); if (titleColor != null) { textView.setTextColor(titleColor); } return textView; }