Java Code Examples for android.widget.GridLayout#addView()
The following examples show how to use
android.widget.GridLayout#addView() .
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: MainViewer.java From GNSS_Compare with Apache License 2.0 | 6 votes |
/** * Factory method to initialize each text view and add it to the layout * @param view text view to be initialized * @param layout layout to which the view is to be added * @param columnId column of the layout to which the view is to be added */ private void initializeTextView( TextView view, GridLayout layout, int columnId){ layout.addView(view); GridLayout.LayoutParams param = new GridLayout.LayoutParams(); param.height = GridLayout.LayoutParams.WRAP_CONTENT; param.width = GridLayout.LayoutParams.WRAP_CONTENT; param.rightMargin = 5; param.topMargin = 5; view.setTextSize(11); view.setWidth(TEXT_FIELD_WIDTH[columnId]); view.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); param.setGravity(Gravity.CENTER); param.columnSpec = GridLayout.spec(columnId); param.rowSpec = GridLayout.spec(rowId); view.setLayoutParams (param); }
Example 2
Source File: MainViewer.java From GNSS_Compare with Apache License 2.0 | 6 votes |
private void initializeTextView( TextView view, GridLayout layout, int columnId){ layout.addView(view); GridLayout.LayoutParams param = new GridLayout.LayoutParams(); param.height = GridLayout.LayoutParams.WRAP_CONTENT; param.width = GridLayout.LayoutParams.WRAP_CONTENT; param.rightMargin = 5; param.topMargin = 5; view.setTextSize(11); view.setWidth(TEXT_FIELD_WIDTH[columnId]); view.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); param.setGravity(Gravity.CENTER); param.columnSpec = GridLayout.spec(columnId); param.rowSpec = GridLayout.spec(rowId); view.setLayoutParams (param); }
Example 3
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 6 votes |
private View createIcon(GridLayout parent, int rowIndex) { // The icon has a pre-defined width. ImageView icon = new ImageView(parent.getContext()); icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); icon.setBackgroundResource(R.drawable.payments_ui_logo_bg); icon.setImageResource(mOption.getDrawableIconId()); icon.setMaxWidth(mIconMaxWidth); // The icon floats to the right of everything. GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(2, 1)); iconParams.topMargin = mVerticalMargin; ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing); parent.addView(icon, iconParams); icon.setOnClickListener(OptionSection.this); return icon; }
Example 4
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 6 votes |
private View createOptionIcon(GridLayout parent, int rowIndex, boolean editIconExists) { // The icon has a pre-defined width. ImageView optionIcon = new ImageView(parent.getContext()); optionIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); optionIcon.setBackgroundResource(R.drawable.payments_ui_logo_bg); optionIcon.setImageDrawable(mOption.getDrawableIcon()); optionIcon.setMaxWidth(mIconMaxWidth); // Place option icon at column three if no edit icon. int columnStart = editIconExists ? 2 : 3; GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(columnStart, 1)); iconParams.topMargin = mVerticalMargin; parent.addView(optionIcon, iconParams); optionIcon.setOnClickListener(OptionSection.this); return optionIcon; }
Example 5
Source File: MainActivity.java From LaunchTime with GNU General Public License v3.0 | 5 votes |
private void showNoIconsRecv(Message msg) { Bundle data = msg.getData(); String category = data.getString("category"); GridLayout iconSheet = mIconSheets.get(category); if (iconSheet!=null) { TextView v = new TextView(this); v.setText(R.string.nothing_in_cat); v.setTextColor(mStyle.getTextColor()); v.setTextSize(mStyle.getLauncherFontSize()); v.setPadding(2,40,2,2); v.setMaxLines(3); iconSheet.addView(v); } }
Example 6
Source File: MainActivity.java From LaunchTime with GNU General Public License v3.0 | 5 votes |
private void addAppToIconSheet(GridLayout iconSheet, AppLauncher app, int pos, boolean reuse) { if (app != null) { try { if (((app.isWidget() || app.isLink()) && isAppInstalled(app.getPackageName())) || mLaunchApp.isValidActivity(app)) { ViewGroup item = getLauncherView(app, false, reuse); if (item != null) { if (!app.iconLoaded()) { app.loadAppIconAsync(this); } item.setTranslationX(0); ViewGroup parent = (ViewGroup) item.getParent(); if (parent != null) parent.removeView(item); GridLayout.LayoutParams lp = getAppLauncherLayoutParams(iconSheet, app); iconSheet.addView(item, pos, lp); } } else { db().deleteApp(app.getComponentName()); Log.d(TAG, "removed " + app.getPackageName() + " " + app.getActivityName() + ": activity not valid."); } } catch (Exception e) { Log.e(TAG, "exception adding icon to sheet", e); Toast.makeText(this,"Couldn't place icon: " + e.getMessage(), Toast.LENGTH_LONG).show(); } } else { Log.d(TAG, "Not showing recent: Null."); } }
Example 7
Source File: StdGameActivity.java From Primary with GNU General Public License v3.0 | 5 votes |
private void setColumnCount(GridLayout answerarea, int count) { List<View> kids = new ArrayList<>(); for(int i = 0; i< answerarea.getChildCount(); i++) { kids.add(answerarea.getChildAt(i)); } answerarea.removeAllViews(); answerarea.setColumnCount(count); for (View k: kids) { k.setLayoutParams(new GridLayout.LayoutParams()); answerarea.addView(k); } }
Example 8
Source File: ScoresActivity.java From Primary with GNU General Public License v3.0 | 5 votes |
private void addTextView(GridLayout viewg, String text, float fsize, int lpadding) { TextView tview = new TextView(this); tview.setTextSize(fsize); tview.setPadding(lpadding + 16, 6, 6, 6); tview.setText(text); viewg.addView(tview); }
Example 9
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
private View createEditIcon(GridLayout parent, int rowIndex) { View editorIcon = LayoutInflater.from(parent.getContext()) .inflate(R.layout.payment_option_edit_icon, null); // The icon floats to the right of everything. GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(3, 1)); iconParams.topMargin = mVerticalMargin; parent.addView(editorIcon, iconParams); editorIcon.setOnClickListener(OptionSection.this); return editorIcon; }
Example 10
Source File: TGABitmapViewerActivity.java From TGAReader with MIT License | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GridLayout layout = new GridLayout(this); ScrollView scroll = new ScrollView(this); scroll.addView(layout); setContentView(scroll); try { String [] list = getAssets().list("images"); // count tga images int count = 0; for(int i=0; i<list.length; i++) { if(list[i].endsWith(".tga")) count++; } layout.setColumnCount(3); layout.setRowCount(count/3); // create tga image view for(int i=0; i<list.length; i++) { if(list[i].endsWith(".tga")) { LinearLayout view = createTGAView(list[i]); if(view != null) layout.addView(view); } } } catch (IOException e) { e.printStackTrace(); } }
Example 11
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 4 votes |
private TextView createLabel( GridLayout parent, int rowIndex, boolean iconExists, boolean isEnabled) { Context context = parent.getContext(); Resources resources = context.getResources(); // By default, the label appears to the right of the "button" in the second column. // + If there is no button and no icon, the label spans the whole row. // + If there is no icon, the label spans two columns. // + Otherwise, the label occupies only its own column. int columnStart = 1; int columnSpan = iconExists ? 1 : 2; TextView labelView = new TextView(context); if (mRowType == OPTION_ROW_TYPE_OPTION) { // Show the string representing the PaymentOption. ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled ? R.style.PaymentsUiSectionDefaultText : R.style.PaymentsUiSectionDisabledText); labelView.setText(convertOptionToString(mOption)); labelView.setEnabled(isEnabled); } else if (mRowType == OPTION_ROW_TYPE_ADD) { // Shows string saying that the user can add a new option, e.g. credit card no. String typeface = resources.getString(R.string.roboto_medium_typeface); int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle); int buttonHeight = resources.getDimensionPixelSize( R.dimen.payments_section_add_button_height); ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionAddButtonLabel); labelView.setMinimumHeight(buttonHeight); labelView.setGravity(Gravity.CENTER_VERTICAL); labelView.setTypeface(Typeface.create(typeface, textStyle)); } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) { // The description spans all the columns. columnStart = 0; columnSpan = 3; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionDescriptiveText); } else if (mRowType == OPTION_ROW_TYPE_WARNING) { // Warnings use two columns. columnSpan = 2; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionWarningText); } // The label spans two columns if no icon exists. Setting the view width to 0 // forces it to stretch. GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(columnStart, columnSpan, GridLayout.FILL)); labelParams.topMargin = mVerticalMargin; labelParams.width = 0; parent.addView(labelView, labelParams); labelView.setOnClickListener(OptionSection.this); return labelView; }
Example 12
Source File: SortingActivity.java From Primary with GNU General Public License v3.0 | 4 votes |
@Override protected void onShowProbImpl() { GridLayout sortArea = findViewById(R.id.sort_area); sortArea.removeAllViews(); sortArea.setOnDragListener(this); Set<Integer> nums = new TreeSet<>(); SortingLevel level = ((SortingLevel) getLevel()); String numliststr = getSavedLevelValue("numlist", (String) null); if (numliststr == null || numliststr.length() == 0) { int tries = 0; do { nums.add(getRand(level.getMaxNum())); } while (tries++ < 100 && nums.size() < level.getNumItems()); numlist = new ArrayList<>(nums); do { Collections.shuffle(numlist); } while (isSorted(numlist)); } else { numlist = splitInts(",", numliststr); deleteSavedLevelValue("numlist"); } int mlen = (level.getMaxNum() + "").length(); // int xsize = getScreenSize().x; // // int tsize = xsize*2/3 / numcolumns / 4 - 5; // if (tsize>30) tsize = 30; int tsize = 30 - mlen; for (int num : numlist) { String spaces = ""; for (int i = 0; i < Math.max(3, mlen) - (num + "").length(); i++) { spaces += " "; } final String numstr = spaces + num; TextView item = new TextView(this); item.setText(numstr); item.setTag(num); item.setOnTouchListener(this); item.setOnDragListener(this); item.setMaxLines(1); item.setTextSize(tsize); item.setTypeface(Typeface.MONOSPACE); //item.setWidth(xsize*2/3 / numcolumns -10); //item.setEms(mlen); item.setGravity(Gravity.END); GridLayout.LayoutParams lp = new GridLayout.LayoutParams(); lp.setMargins(1, 1, 1, 1); lp.setGravity(Gravity.CENTER); item.setLayoutParams(lp); item.setBackgroundColor(BACKGROUND_COLOR); item.setPadding(16, 12, 16, 12); sortArea.addView(item); } problemDone = false; moves = 0; setFasttimes(level.getNumItems()*300, level.getNumItems()*500, level.getNumItems()*750); startHint(level.getNumItems()); }
Example 13
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 4 votes |
private TextView createLabel(GridLayout parent, int rowIndex, boolean optionIconExists, boolean editIconExists, boolean isEnabled) { Context context = parent.getContext(); Resources resources = context.getResources(); // By default, the label appears to the right of the "button" in the second column. // + If there is no button, no option and edit icon, the label spans the whole row. // + If there is no option and edit icon, the label spans three columns. // + If there is no edit icon or option icon, the label spans two columns. // + Otherwise, the label occupies only its own column. int columnStart = 1; int columnSpan = 1; if (!optionIconExists) columnSpan++; if (!editIconExists) columnSpan++; TextView labelView = new TextView(context); if (mRowType == OPTION_ROW_TYPE_OPTION) { // Show the string representing the PaymentOption. ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled ? R.style.PaymentsUiSectionDefaultText : R.style.PaymentsUiSectionDisabledText); labelView.setText(convertOptionToString( mOption, mDelegate.isBoldLabelNeeded(OptionSection.this))); labelView.setEnabled(isEnabled); } else if (mRowType == OPTION_ROW_TYPE_ADD) { // Shows string saying that the user can add a new option, e.g. credit card no. String typeface = resources.getString(R.string.roboto_medium_typeface); int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle); int buttonHeight = resources.getDimensionPixelSize( R.dimen.payments_section_add_button_height); ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionAddButtonLabel); labelView.setMinimumHeight(buttonHeight); labelView.setGravity(Gravity.CENTER_VERTICAL); labelView.setTypeface(Typeface.create(typeface, textStyle)); } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) { // The description spans all the columns. columnStart = 0; columnSpan = 4; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionDescriptiveText); } else if (mRowType == OPTION_ROW_TYPE_WARNING) { // Warnings use three columns. columnSpan = 3; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionWarningText); } // The label spans two columns if no option or edit icon, or spans three columns if // no option and edit icons. Setting the view width to 0 forces it to stretch. GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(columnStart, columnSpan, GridLayout.FILL)); labelParams.topMargin = mVerticalMargin; labelParams.width = 0; if (optionIconExists) { // Margin at the end of the label instead of the start of the option icon to // allow option icon in the the next row align with the end of label (include // end margin) when edit icon exits in that row, like below: // ---Label---------------------[label margin]|---option icon---| // ---Label---[label margin]|---option icon---|----edit icon----| ApiCompatibilityUtils.setMarginEnd(labelParams, mLargeSpacing); } parent.addView(labelView, labelParams); labelView.setOnClickListener(OptionSection.this); return labelView; }
Example 14
Source File: TVShowProgressFragment.java From Kore with Apache License 2.0 | 4 votes |
/** * Display the seasons list * * @param cursor Cursor with the data */ @TargetApi(21) private void displaySeasonList(Cursor cursor) { TextView seasonsListTitle = (TextView) getActivity().findViewById(R.id.seasons_title); GridLayout seasonsList = (GridLayout) getActivity().findViewById(R.id.seasons_list); if (cursor.moveToFirst()) { seasonsListTitle.setVisibility(View.VISIBLE); seasonsList.setVisibility(View.VISIBLE); HostManager hostManager = HostManager.getInstance(getActivity()); View.OnClickListener seasonListClickListener = new View.OnClickListener() { @Override public void onClick(View v) { listenerActivity.onSeasonSelected(itemId, (int)v.getTag()); } }; // Get the art dimensions Resources resources = getActivity().getResources(); int artWidth = (int)(resources.getDimension(R.dimen.seasonlist_art_width) / UIUtils.IMAGE_RESIZE_FACTOR); int artHeight = (int)(resources.getDimension(R.dimen.seasonlist_art_heigth) / UIUtils.IMAGE_RESIZE_FACTOR); // Get theme colors Resources.Theme theme = getActivity().getTheme(); TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.colorInProgress, R.attr.colorFinished }); int inProgressColor = styledAttributes.getColor(styledAttributes.getIndex(0), resources.getColor(R.color.orange_500)); int finishedColor = styledAttributes.getColor(styledAttributes.getIndex(1), resources.getColor(R.color.green_400)); styledAttributes.recycle(); seasonsList.removeAllViews(); do { int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON); String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL); int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE); int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES); View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList, false); ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art); TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season); TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes); ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar); seasonNumberView.setText(String.format(getActivity().getString(R.string.season_number), seasonNumber)); seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes), numEpisodes, numEpisodes - watchedEpisodes)); seasonProgressBar.setMax(numEpisodes); seasonProgressBar.setProgress(watchedEpisodes); if (Utils.isLollipopOrLater()) { int watchedColor = (numEpisodes - watchedEpisodes == 0) ? finishedColor : inProgressColor; seasonProgressBar.setProgressTintList(ColorStateList.valueOf(watchedColor)); } UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail, String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight); seasonView.setTag(seasonNumber); seasonView.setOnClickListener(seasonListClickListener); seasonsList.addView(seasonView); } while (cursor.moveToNext()); } else { // No seasons, hide views seasonsListTitle.setVisibility(View.GONE); seasonsList.setVisibility(View.GONE); } }