List of usage examples for android.widget TextView setGravity
public void setGravity(int gravity)
From source file:com.mifos.utils.DataTableUIBuilder.java
public LinearLayout getDataTableLayout(final DataTable dataTable, JsonArray jsonElements, LinearLayout parentLayout, final Context context, final int entityId, DataTableActionListener mListener) { dataTableActionListener = mListener; /**//from w w w . j ava2 s .c om * Create a Iterator with Json Elements to Iterate over the DataTable * Response. */ Iterator<JsonElement> jsonElementIterator = jsonElements.iterator(); /* * Each Row of the Data Table is Treated as a Table Here. * Creating the First Table for First Row */ tableIndex = 0; while (jsonElementIterator.hasNext()) { TableLayout tableLayout = new TableLayout(context); tableLayout.setPadding(10, 10, 10, 10); final JsonElement jsonElement = jsonElementIterator.next(); /* * Each Entry in a Data Table is Displayed in the * form of a table where each row contains one Key-Value Pair * i.e a Column Name - Column Value from the DataTable */ int rowIndex = 0; while (rowIndex < dataTable.getColumnHeaderData().size()) { TableRow tableRow = new TableRow(context); tableRow.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); tableRow.setPadding(10, 10, 10, 10); if (rowIndex % 2 == 0) { tableRow.setBackgroundColor(Color.LTGRAY); } else { tableRow.setBackgroundColor(Color.WHITE); } TextView key = new TextView(context); key.setText(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()); key.setGravity(Gravity.LEFT); TextView value = new TextView(context); value.setGravity(Gravity.RIGHT); if (jsonElement.getAsJsonObject().get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()) .toString().contains("\"")) { value.setText(jsonElement.getAsJsonObject() .get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()).toString() .replace("\"", "")); } else { value.setText(jsonElement.getAsJsonObject() .get(dataTable.getColumnHeaderData().get(rowIndex).getColumnName()).toString()); } tableRow.addView(key, new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); tableRow.addView(value, new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.setMargins(12, 16, 12, 16); tableLayout.addView(tableRow, layoutParams); rowIndex++; } tableLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, "Update Row " + tableIndex, Toast.LENGTH_SHORT).show(); } }); tableLayout.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(context, "Deleting Row " + tableIndex, Toast.LENGTH_SHORT).show(); BaseApiManager baseApiManager = new BaseApiManager(); DataManager dataManager = new DataManager(baseApiManager); Observable<GenericResponse> call = dataManager .removeDataTableEntry(dataTable.getRegisteredTableName(), entityId, Integer.parseInt(jsonElement.getAsJsonObject() .get(dataTable.getColumnHeaderData().get(0).getColumnName()) .toString())); Subscription subscription = call.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<GenericResponse>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(GenericResponse genericResponse) { Toast.makeText(context, "Deleted Row " + tableIndex, Toast.LENGTH_SHORT).show(); dataTableActionListener.onRowDeleted(); } }); return true; } }); View v = new View(context); v.setBackgroundColor(ContextCompat.getColor(context, R.color.black)); parentLayout.addView(tableLayout); parentLayout.addView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 5)); Log.i("TABLE INDEX", "" + tableIndex); tableIndex++; } return parentLayout; }
From source file:com.art2cat.dev.moonlightnote.controller.settings.CommonSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment if (getArguments() != null) { mType = getArguments().getInt("type"); }/*from w w w . jav a2s . co m*/ LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); linearLayout.setLayoutParams(params); ScrollView scrollView = new ScrollView(getActivity()); scrollView.setLayoutParams(params); linearLayout.addView(scrollView); TextView textView = new TextView(getActivity()); textView.setLayoutParams(params); int padding = getResources().getDimensionPixelOffset(R.dimen.padding); textView.setPadding(padding, padding, padding, padding); switch (mType) { case Constants.FRAGMENT_ABOUT: textView.setGravity(Gravity.CENTER); textView.setText(getContent()); getActivity().setTitle(R.string.settings_about); break; case Constants.FRAGMENT_LICENSE: textView.setGravity(Gravity.CENTER); textView.setText(getContent()); getActivity().setTitle(R.string.settings_license); break; case Constants.FRAGMENT_POLICY: textView.setGravity(Gravity.START); textView.setText(getContent()); getActivity().setTitle(R.string.settings_policy); break; } setHasOptionsMenu(true); scrollView.addView(textView); return linearLayout; }
From source file:br.unb.mobileMedia.core.view.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. * <p/>// w ww .j ava2 s. co 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 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) { FrameLayout root = new FrameLayout(getActivity()); FrameLayout lframe = new FrameLayout(getActivity()); 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)); ListView.LayoutParams lp = new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); root.setLayoutParams(lp); return root; }
From source file:com.android.messaging.ui.ViewPagerTabs.java
private void addTab(CharSequence tabTitle, final int position) { final TextView textView = new TextView(getContext()); textView.setText(tabTitle);/*from ww w. j a v a2s .c om*/ textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector); textView.setGravity(Gravity.CENTER); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(getRtlPosition(position)); } }); // Assign various text appearance related attributes to child views. if (mTextStyle > 0) { textView.setTypeface(textView.getTypeface(), mTextStyle); } if (mTextSize > 0) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } if (mTextColor != null) { textView.setTextColor(mTextColor); } textView.setAllCaps(mTextAllCaps); textView.setPadding(mSidePadding, 0, mSidePadding, 0); mTabStrip.addView(textView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1)); // Default to the first child being selected if (position == 0) { mPrevSelected = 0; textView.setSelected(true); } }
From source file:com.consumer.widget.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)}./*from w ww .j a v a 2 s. c o m*/ */ @SuppressLint("NewApi") protected TextView createDefaultTabView(Context context) { Resources res = context.getResources(); TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); //textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); //textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTextSize(TAB_VIEW_TEXT_SIZE_SP); //textView.setTypeface(Typeface.DEFAULT_BOLD); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f); textView.setLayoutParams(param); int unSelColorBg = R.color.TabPager; textView.setTextColor(context.getResources().getColor(unSelColorBg)); 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); textView.setPadding(5, 17, 5, 22); return textView; }
From source file:com.dreamspace.superman.UI.View.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)}./*ww w .j a v a 2s .c om*/ */ protected View createDefaultTabView(Context context) { View v; if (mIconAdapter == null) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT); textView.setAllCaps(true); textView.setTextColor(getStartColor()); if (fillTheWidth) { textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1)); } else { textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); } ; v = textView; } else { ImageView imgView = new TintImageView(context); imgView.setScaleType(ImageView.ScaleType.FIT_XY); imgView.setLayoutParams(new LinearLayout.LayoutParams(mTabIconSize, mTabIconSize)); v = imgView; } TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); v.setBackgroundResource(outValue.resourceId); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); v.setPadding(padding, padding, padding, padding); return v; }
From source file:com.duckduckgo.mobile.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)}./* www .j a v a 2 s. com*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.TOP | Gravity.CENTER); textView.setTextAppearance(context, R.style.TabTitle); textView.setHeight((int) getResources().getDimension(R.dimen.actionbar_tab_height2)); 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); int halfPadding = (int) (padding * 0.5); //textView.setPadding(padding, padding, padding, padding); textView.setPadding(padding, halfPadding, padding, padding); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int width; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Point size = new Point(); display.getSize(size); width = size.x; } else { width = display.getWidth(); } if (width > getResources().getDimension(R.dimen.tab_small) || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { textView.setWidth(width / mViewPager.getAdapter().getCount()); } return textView; }
From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java
@SuppressLint("NewApi") @Override//from w w w .j a va 2s . c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState)); View rootView = inflater.inflate(R.layout.fragment_summary, container, false); final MainActivity activity = (MainActivity) getActivity(); final Context context = activity; final Resources resources = context.getResources(); // Get the model and attach a listener. game = activity.getGame(); if (game != null) { game.addListener(mGameListener); } players = activity.getPlayers(); // Get resources. String[] playerNames = resources.getStringArray(R.array.playerNames); TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables); TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors); int[] playerTextColorsIds = new int[playerTextColorsArray.length()]; for (int i = 0; i < playerTextColorsArray.length(); i++) { playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1); } // Get root view. ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view); // Create table. tableLayout = new TableLayout(context); TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tableLayout.setLayoutParams(tableLayoutParams); scrollView.addView(tableLayout); // Add header. { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.player)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.trains)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.contracts)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.bonuses)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); } // Add rows. for (int i = 0; i < players.getNum(); i++) { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); ToggleButton toggleButton = new ToggleButton(context); toggleButton.setGravity(Gravity.CENTER); toggleButton.setPadding(10, 10, 10, 10); toggleButton.setText(playerNames[i]); toggleButton.setClickable(false); Drawable drawable = drawablesArray.getDrawable(i); int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { toggleButton.setBackgroundDrawable(drawable); } else { toggleButton.setBackground(drawable); } toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i])); row.addView(toggleButton); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); } Bundle args = getArguments(); if (args == null) { Log.e(TAG, "onCreateView: missing arguments"); return rootView; } drawablesArray.recycle(); playerTextColorsArray.recycle(); // final int index = args.getInt(ARG_INDEX); // final String tabSpec = args.getString(ARG_TAB_SPEC); return rootView; }
From source file:com.ikode.viezara.ikode.HelpPage.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_help_page); listView = (ListView) findViewById(R.id.list); searchBox = (SearchView) findViewById(R.id.searchbox); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, titles); listView.setAdapter(adapter);//from w ww. j a v a 2 s. co m searchBox.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextSubmit(String query) { // TODO Auto-generated method stub return false; } public boolean onQueryTextChange(String query) { // TODO Auto-generated method stub adapter.getFilter().filter(query); return false; } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String chosenTitle = ((TextView) view).getText().toString(); String titleValue = getValue(chosenTitle); TextView tx = new TextView(HelpPage.this); tx.setText(titleValue); tx.setGravity(Gravity.TOP); new AlertDialog.Builder(HelpPage.this).setTitle("MESSAGE").setMessage("CONTENT: ") .setView(tx, 25, 0, 25, 0) .setNegativeButton("CLOSE", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }).show(); } }); //Toolbar toolbar = (Toolbar) findViewById(R.id.ikode_bar); // setSupportActionBar(toolbar); //test for returning to previous activity // getSupportActionBar().setHomeButtonEnabled(true); //getSupportActionBar().setDisplayHomeAsUpEnabled(true); /* try { parseData(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "ERROR: " + e.getMessage(), Toast.LENGTH_LONG).show(); } */ //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.Layout.simple_List_item_1, searches ); /*SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName componentName = new ComponentName(context, HelpPage.class); searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName));*/ }
From source file:com.kobi.metalsexchange.app.component.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)}./*from ww w .j a v a 2s . c o m*/ */ protected TextView createDefaultTabView(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); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); 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; }