List of usage examples for android.widget TableLayout addView
@Override public void addView(View child, ViewGroup.LayoutParams params)
From source file:au.org.ala.fielddata.mobile.SurveyBuilder.java
private void addRow(TableLayout tableLayout, TableRow row) { TableRow.LayoutParams params = new TableRow.LayoutParams(); params.setMargins(5, 5, 10, 10);/*from w w w . j a v a 2 s .com*/ params.width = TableRow.LayoutParams.MATCH_PARENT; params.height = TableRow.LayoutParams.WRAP_CONTENT; tableLayout.addView(row, params); }
From source file:com.murrayc.galaxyzoo.app.QuestionFragment.java
private static TableRow addRowToTable(final Activity activity, final TableLayout layoutAnswers) { final TableRow row = new TableRow(activity); final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT); //Add a top margin between this row and any row above it: if (layoutAnswers.getChildCount() > 0) { final int margin = UiUtils.getPxForDpResource(activity, R.dimen.tiny_gap); params.setMargins(0, margin, 0, 0); }/* w w w.j a v a 2 s .com*/ layoutAnswers.addView(row, params); return row; }
From source file:com.murrayc.galaxyzoo.app.QuestionHelpFragment.java
private void addRowForAnswer(final Context context, final TableLayout tableLayout, final DecisionTree.Question question, final DecisionTree.BaseButton answer) { final TableRow row = new TableRow(context); final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin), 0, 0); tableLayout.addView(row, params); final LinearLayout layoutVertical = new LinearLayout(context); layoutVertical.setOrientation(LinearLayout.VERTICAL); final TextView textViewAnswer = new AppCompatTextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textViewAnswer.setTextAppearance(R.style.TextAppearance_AppCompat_Subhead); } else {//from w w w. j a va2s . c o m //noinspection deprecation textViewAnswer.setTextAppearance(context, R.style.TextAppearance_AppCompat_Subhead); } textViewAnswer.setText(answer.getText()); layoutVertical.addView(textViewAnswer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutHorizontal = new LinearLayout(context); layoutHorizontal.setOrientation(LinearLayout.HORIZONTAL); final LinearLayout.LayoutParams paramsHorizontal = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); paramsHorizontal.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_margin), 0, 0); layoutVertical.addView(layoutHorizontal, paramsHorizontal); final BitmapDrawable icon = getIcon(context, answer); final ImageView imageIcon = new ImageView(context); imageIcon.setImageDrawable(icon); layoutHorizontal.addView(imageIcon); final LinearLayout.LayoutParams paramsImage = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); // TODO: Use a custom FlowTable class to avoid items going off the right edge of the screen // when there are too many. final Singleton singleton = getSingleton(); for (int i = 0; i < answer.getExamplesCount(); i++) { final String iconName = answer.getExampleIconName(question.getId(), i); final BitmapDrawable iconExample = singleton.getIconDrawable(context, iconName); final ImageButton imageExample = new ImageButton(context); //Remove the space between the image and the outside of the button: imageExample.setPadding(0, 0, 0, 0); imageExample.setImageDrawable(iconExample); //Needed to make the image expand as a transition into the SubjectViewerActivity, //which uses the same name in fragment_subject.xml ViewCompat.setTransitionName(imageExample, getString(R.string.transition_subject_image)); //This requires API level 17: paramsImage.setMarginStart(getPxForDp(activity, MARGIN_MEDIUM_DP)); //imageExample.setLayoutParams(paramsImage); MarginLayoutParamsCompat.setMarginStart(paramsImage, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin)); final int answerIndex = i; imageExample.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onExampleImageClicked(v, answer, answerIndex); } }); layoutHorizontal.addView(imageExample, paramsImage); } row.addView(layoutVertical, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); }
From source file:com.google.reviewit.AddReviewerFragment.java
private void displayCCs(Change change) { TableLayout tl = (TableLayout) v(R.id.reviewerTable); Collection<AccountInfo> ccs = change.ccs(); if (!ccs.isEmpty()) { TableRow tr = new TableRow(getContext()); tr.setLayoutParams(matchAndWrapTableRowLayout()); TextView ccsTitle = new TextView(getContext()); TableRow.LayoutParams params = wrapTableRowLayout(2); params.bottomMargin = widgetUtil.dpToPx(3); ccsTitle.setLayoutParams(params); ccsTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); ccsTitle.setText(getString(R.string.ccs)); tr.addView(ccsTitle);//from w w w.ja va 2 s . c o m tl.addView(tr, matchAndWrapTableLayout()); for (AccountInfo cc : ccs) { addReviewerRow(tl, cc); } } }
From source file:aws.apps.underthehood.Main.java
private void listToTable(List<String> l, TableLayout t, LayoutParams lp) { String chr;//from ww w .ja v a2s . c o m String seperator = getString(R.string.seperator_identifier); try { if (l.size() == 0) { return; } for (int i = 0; i < l.size(); i++) { chr = l.get(i).substring(0, 1); if (chr.equals("#") || chr.equals("$") || chr.equals(">")) { t.addView(gui.createTitleRow(l.get(i)), lp); } else if (chr.equals(seperator)) { t.addView(gui.createSeperatorRow(l.get(i)), lp); } else { t.addView(gui.createDataRow(l.get(i)), lp); } } } catch (Exception e) { Log.e(TAG, "^ listToTable() Exception: " + e.getMessage()); } }
From source file:com.google.reviewit.AddReviewerFragment.java
private void addReviewerRow(TableLayout tl, AccountInfo reviewer) { TableRow tr = new TableRow(getContext()); tr.setLayoutParams(matchAndWrapTableRowLayout()); ImageView avatar = new ImageView(getContext()); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(widgetUtil.dpToPx(20), widgetUtil.dpToPx(20));/*from w ww. j a v a 2 s. c om*/ layoutParams.setMargins(0, 0, widgetUtil.dpToPx(5), widgetUtil.dpToPx(2)); avatar.setLayoutParams(layoutParams); WidgetUtil.displayAvatar(getApp(), reviewer, avatar); tr.addView(avatar); TextView reviewerName = new TextView(getContext()); reviewerName.setLayoutParams(wrapTableRowLayout()); reviewerName.setText(FormatUtil.format(reviewer)); tr.addView(reviewerName); tl.addView(tr, matchAndWrapTableLayout()); }
From source file:org.aquabase.DetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { View rootView = inflater.inflate(R.layout.fragment_details, container, false); // Fill the table layout with rows for the fields depending on the item TableLayout table = (TableLayout) rootView.findViewById(R.id.TableLayout); for (int i = 0; i < mLabelIds.size(); i++) { // Don't switch to an inflated XML file for each row: way too slow TableRow row = new TableRow(getActivity()); row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); row.setPadding(0, 3, 0, 3);/*from w w w . ja va2s.c o m*/ TextView titleView = new TextView(getActivity()); titleView.setText(mLabelIds.get(i)); titleView.setPadding(0, 0, 12, 0); titleView.setGravity(Gravity.TOP); titleView.setTypeface(Typeface.DEFAULT_BOLD); row.addView(titleView); TextView valueView = new TextView(getActivity()); valueView.setText(mValues.get(i)); titleView.setGravity(Gravity.TOP); row.addView(valueView); table.addView(row, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); } return rootView; }
From source file:org.mifos.androidclient.main.DepositDueDetailsActivity.java
private void updateContent(SavingsAccountDepositDue details) { mDetails = details;// www.ja v a 2s.c o m TextView cell; Double nextDeposit, pastDepositAmount, pastDepositsSum = 0.0; cell = (TextView) findViewById(R.id.depositDueDetails_nextDeposit); nextDeposit = details.getNextDueDetail().getDueAmount(); cell.setText(nextDeposit.toString()); if (ValueUtils.hasElements(details.getPreviousDueDetails())) { TableLayout table = (TableLayout) findViewById(R.id.depositDueDetails_table); View view = findViewById(R.id.depositDueDetails_rowInsertPoint); int index = table.indexOfChild(view) + 1; view = findViewById(R.id.depositDueDetails_subTotal_label); TableLayoutHelper helper = new TableLayoutHelper(this, TableLayoutHelper.DEFAULT_TABLE_ROW_SEPARATOR_HEIGHT, view.getPaddingLeft(), view.getPaddingRight()); for (DueOnDate pastDeposit : details.getPreviousDueDetails()) { if (pastDeposit.getDueDate().before(details.getNextDueDetail().getDueDate())) { TableRow row = helper.createTableRow(); cell = helper.createTableCell(DateUtils.format(pastDeposit.getDueDate()), 1); row.addView(cell); pastDepositAmount = pastDeposit.getDueAmount(); cell = helper.createTableCell(pastDepositAmount.toString(), 2); row.addView(cell); table.addView(row, index); index++; table.addView(helper.createRowSeparator(), index); index++; pastDepositsSum += pastDepositAmount; } } } cell = (TextView) findViewById(R.id.depositDueDetails_subTotal); cell.setText(pastDepositsSum.toString()); cell = (TextView) findViewById(R.id.depositDueDetails_totalAmountDue_label); cell.setText(cell.getText() + DateUtils.format(details.getNextDueDetail().getDueDate())); cell = (TextView) findViewById(R.id.depositDueDetails_totalAmountDue); cell.setText(Double.toString(pastDepositsSum + nextDeposit)); }
From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java
@TargetApi(11) private static int createStandardRow(Fragment fragment, TableLayout tableLayout, List<Stock> stocks, SparseArray<View> tiles, int height, int margin, int index, int row) { Stock stock1 = stocks.get(index);// w ww. j a v a2s. c om Stock stock2 = (index + 1 < stocks.size()) ? stocks.get(index + 1) : null; if (shouldUpdateTableRow(tableLayout, row, stock1, stock2)) { TableRow tableRow = new TableRow(fragment.getActivity()); boolean shouldSpanFirstTile = row % 2 != 0; boolean shouldSpanSecondTile = !shouldSpanFirstTile; if (stock2 != null) { View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile); tiles.put(index, tile1); tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin) : getNotSpannedLayoutParams(row, height, margin)); View tile2 = createTile(fragment, stock2, index + 1, shouldSpanSecondTile); tiles.put(index + 1, tile2); tableRow.addView(tile2, shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin) : getLastNotSpannedLayoutParams(row, height, margin)); } else { View tile1 = createTile(fragment, stock1, index, shouldSpanFirstTile); tiles.put(index, tile1); tableRow.addView(tile1, shouldSpanFirstTile ? getPartialSpannedLayoutParams(row, height, margin) : getNotSpannedLayoutParams(row, height, margin)); View tile2 = createTileForAddingNewStock(fragment); tiles.put(index + 1, tile2); tableRow.addView(tile2, shouldSpanSecondTile ? getLastPartialSpannedLayoutParams(row, height, margin) : getLastNotSpannedLayoutParams(row, height, margin)); } if (row < tableLayout.getChildCount()) { tableLayout.removeViewAt(row); } tableLayout.addView(tableRow, row); } return index + 2; }
From source file:com.example.hllut.app.Deprecated.MainActivity.java
/** * fill the "liters of petrol" textView, as well as drawing the petrol barrels */// w w w. j ava 2 s . co m private void drawPetrol() { //TODO use the bundle float litersOfPetrol = (TOTAL_CO2 / CO2_PER_LITRE_PETROL); TextView tv = (TextView) findViewById(R.id.litersTextView); tv.setText("Burning " + String.format("%.2f", litersOfPetrol) + " liters of petrol"); TableLayout layout = (TableLayout) findViewById(R.id.petrolContainer); TableRow newRow = new TableRow(this); LinearLayout linLay = new LinearLayout(this); linLay.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); newRow.setLayoutParams( new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); newRow.setPadding(10, 10, 10, 10); for (int i = 1; i < (int) litersOfPetrol + 1; i++) { // // TODO: To many images fuck up formatting // Create images ImageView im = new ImageView(this); im.setImageResource(R.drawable.oil_barrel); im.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); //barrells per row = 7 if (i % 7 == 0) { // if you have gone 7 laps // print what you have linLay.addView(im); newRow.addView(linLay, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); layout.addView(newRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); newRow = new TableRow(this); linLay = new LinearLayout(this); linLay.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); newRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); newRow.setPadding(10, 10, 10, 10); } else { linLay.addView(im); } } newRow.addView(linLay, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); layout.addView(newRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); }