Java Code Examples for android.widget.TableLayout#LayoutParams
The following examples show how to use
android.widget.TableLayout#LayoutParams .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewUtil.java From TitleBarView with Apache License 2.0 | 6 votes |
/** * 设置View的Margin * * @param view * @param left * @param top * @param right * @param bottom * @param width * @param height */ public void setViewMargin(View view, int left, int top, int right, int bottom, int width, int height) { if (view == null) { return; } ViewParent parent = view.getParent(); if (parent == null) { return; } ViewGroup.MarginLayoutParams lp; if (parent instanceof LinearLayout) { lp = new LinearLayout.LayoutParams(width, height); } else if (parent instanceof RelativeLayout) { lp = new RelativeLayout.LayoutParams(width, height); } else if (parent instanceof FrameLayout) { lp = new FrameLayout.LayoutParams(width, height); } else { lp = new TableLayout.LayoutParams(width, height); } if (lp != null) { lp.setMargins(left, top, right, bottom); view.setLayoutParams(lp); } }
Example 2
Source File: ViewUtil.java From UIWidget with Apache License 2.0 | 6 votes |
/** * 设置View的Margin * * @param view * @param left * @param top * @param right * @param bottom * @param width * @param height */ public void setViewMargin(View view, int left, int top, int right, int bottom, int width, int height) { if (view == null) { return; } ViewParent parent = view.getParent(); if (parent == null) { return; } ViewGroup.MarginLayoutParams lp; if (parent instanceof LinearLayout) { lp = new LinearLayout.LayoutParams(width, height); } else if (parent instanceof RelativeLayout) { lp = new RelativeLayout.LayoutParams(width, height); } else if (parent instanceof FrameLayout) { lp = new FrameLayout.LayoutParams(width, height); } else { lp = new TableLayout.LayoutParams(width, height); } if (lp != null) { lp.setMargins(left, top, right, bottom); view.setLayoutParams(lp); } }
Example 3
Source File: QuestionFragment.java From android-galaxyzoo with GNU General Public License v3.0 | 6 votes |
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); } layoutAnswers.addView(row, params); return row; }
Example 4
Source File: NoteFragment.java From 4pdaClient-plus with Apache License 2.0 | 5 votes |
private void fillData(final Note note) { try { setTitle(DbHelper.getDateString(note.Date)); infoTable.removeAllViews(); TableLayout.LayoutParams rowparams = new TableLayout.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); TableRow.LayoutParams textviewparams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); if (!TextUtils.isEmpty(note.Title)) { addRow(getString(R.string.theme), note.Title, null, rowparams, textviewparams); } if (!TextUtils.isEmpty(note.Topic)) { addRow(getString(R.string.topic), note.getTopicLink(), note.getTopicUrl(), rowparams, textviewparams); } if (!TextUtils.isEmpty(note.User)) { addRow(getString(R.string.user), note.getUserLink(), note.getUserUrl(), rowparams, textviewparams); } if (!TextUtils.isEmpty(note.Url)) { addRow(getString(R.string.link), note.getUrlLink(), note.Url, rowparams, textviewparams); } webView.loadDataWithBaseURL("https://4pda.ru/forum/", transformChatBody(note.Body), "text/html", "UTF-8", null); } catch (Throwable ex) { AppLog.e(getMainActivity(), ex); } }
Example 5
Source File: TimetableView.java From TimetableView with Apache License 2.0 | 4 votes |
private TableLayout.LayoutParams createTableLayoutParam() { return new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT); }
Example 6
Source File: CheckersLayout.java From privacy-friendly-dame with GNU General Public License v3.0 | 4 votes |
public CheckersLayout(CheckersGame game, GameActivity activity) { super(activity); myActivity = activity; DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); int dimension = displayMetrics.widthPixels; if (displayMetrics.heightPixels < dimension) { dimension = displayMetrics.heightPixels; } int cellDimension = dimension / 8 ; LayoutParams params; myGame = game; Board myBoard = myGame.getBoard(); params = new LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(4, 4, 4, 4); setLayoutParams(params); setBackgroundColor(getResources().getColor(R.color.cellBlack)); // add table of image views cells = new CheckerImageView[8][8]; for (int y = 0; y < 8; y++) { TableRow row = new TableRow(activity); TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tableParams.setMargins(0, 0, 0, 0); row.setLayoutParams(tableParams); for (int x = 0; x < 8; x++) { CheckerImageView cell; cells[x][y] = cell = new CheckerImageView(activity); cell.x = x; cell.y = y; TableRow.LayoutParams rowParams = new TableRow.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); rowParams.setMargins(0, 0, 0, 0); rowParams.width = cellDimension; rowParams.height = cellDimension; cell.setLayoutParams(rowParams); int bgColor; if (myBoard.isGameSquare(x,y)) { // add click handler cell.setOnClickListener(CellClick); bgColor = getResources().getColor(R.color.cellBlack); } else { bgColor = getResources().getColor(R.color.cellWhite); } cell.setBackgroundColor(bgColor); row.addView(cell); } addView(row); } }
Example 7
Source File: ResultMatrixLayout.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public void resize(int rows, int cols, int cellLayoutId) { if (rowsNumber == rows && colsNumber == cols) { return; } rowsNumber = rows; colsNumber = cols; removeAllViews(); fields.clear(); final TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams( TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT); final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE); for (int row = 0; row < rowsNumber; row++) { final TableRow tableRow = new TableRow(getContext()); tableRow.setLayoutParams(tableParams); // TableLayout is the parent view addView(tableRow); for (int col = 0; col < colsNumber; col++) { inflater.inflate(cellLayoutId, tableRow); } if (tableRow.getChildCount() > 0) { tableRow.setBaselineAligned(true); tableRow.setBaselineAlignedChildIndex(0); } for (int col = 0; col < tableRow.getChildCount(); col++) { final CustomEditText c = (CustomEditText) tableRow.getChildAt(col); if (c != null) { c.setId(IdGenerator.generateId()); c.setTag(new ElementTag(row, col, fields.size())); fields.add(c); } } } setPadding(0, 0, 0, 0); setBaselineAligned(true); setBaselineAlignedChildIndex(rowsNumber > 1 ? rowsNumber / 2 : 0); }
Example 8
Source File: QuestionHelpFragment.java From android-galaxyzoo with GNU General Public License v3.0 | 4 votes |
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 { //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)); }