本文整理匯總了Java中android.support.v7.widget.GridLayout.getContext方法的典型用法代碼示例。如果您正苦於以下問題:Java GridLayout.getContext方法的具體用法?Java GridLayout.getContext怎麽用?Java GridLayout.getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.GridLayout
的用法示例。
在下文中一共展示了GridLayout.getContext方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateColorBlocks
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
public void generateColorBlocks(int[] colors, GridLayout layout) {
int column = 3;
int total = colors.length;
int rows = total / column;
layout.setColumnCount(column);
layout.setRowCount(rows + 1);
for (int i = 0, c = 0, r = 0; i < total; i++, c++) {
if (c == column) {
c = 0;
r++;
}
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.rowSpec = GridLayout.spec(r);
layoutParams.columnSpec = GridLayout.spec(c);
layoutParams.setGravity(Gravity.CENTER);
ImageView imageView = new ImageView(layout.getContext());
imageView.setBackgroundColor(colorsParam[i]);
imageView.setLayoutParams(layoutParams);
layout.addView(imageView);
}
}
示例2: createOptionIcon
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
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);
if (mOption.isEditable()) {
optionIcon.setMaxWidth(mEditableOptionIconMaxWidth);
} else {
optionIcon.setMaxWidth(mNonEditableOptionIconMaxWidth);
}
optionIcon.setAdjustViewBounds(true);
optionIcon.setImageDrawable(mOption.getDrawableIcon());
// 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, GridLayout.CENTER));
iconParams.topMargin = mVerticalMargin;
parent.addView(optionIcon, iconParams);
optionIcon.setOnClickListener(OptionSection.this);
return optionIcon;
}
示例3: createLabel
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
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),
false /* singleLine */));
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, 1f));
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;
}