本文整理匯總了Java中android.support.v7.widget.GridLayout.addView方法的典型用法代碼示例。如果您正苦於以下問題:Java GridLayout.addView方法的具體用法?Java GridLayout.addView怎麽用?Java GridLayout.addView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.GridLayout
的用法示例。
在下文中一共展示了GridLayout.addView方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: populateFavorites
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
private void populateFavorites(List<Song> favorites)
{
if(favorites != null)
{
GridLayout favoritesLayout = (GridLayout)getView().findViewById(R.id.favorites_layout);
float favWidth = getContext().getResources().getDimension(R.dimen.album_grid_item_width);
float favHeight = getContext().getResources().getDimension(R.dimen.album_grid_item_height);
LayoutInflater inflater = LayoutInflater.from(getContext());
int max = Math.min(favorites.size(),3);
for(int i = 0; i < max; i++)
{
Song song = favorites.get(i);
View v = inflater.inflate(R.layout.album_grid_item, favoritesLayout, false);
favoritesLayout.addView(v);
ImageView artworkView = (ImageView) v.findViewById(R.id.album_artwork);
}
}
}
示例2: SuggestionViewHolder
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
public SuggestionViewHolder(View itemView) {
super(itemView);
suggestionRelative = (RelativeLayout) itemView.findViewById(R.id.suggestion_detail);
suggestionDetailIcon = (ImageView) itemView.findViewById(R.id.suggestion_detail_icon);
suggestionDetailInfo = (TextView) itemView.findViewById(R.id.suggestion_detail_info);
suggestionDetailIntroduction = (TextView) itemView.findViewById(R.id.suggestion_detail_introduction);
suggestionGrid = (GridLayout) itemView.findViewById(R.id.suggestion_grid);
for (int i = 0; i < 6; i++) {
View view = View.inflate(mContext, R.layout.item_suggestion_grid, null);
view.setId(R.id.suggestion_view_id + i);
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
params.setMargins(90, 15, 0, 15);//設置邊距
view.setLayoutParams(params);
suggestionType[i] = (TextView) view.findViewById(R.id.suggestion_type);
suggestionInfo[i] = (TextView) view.findViewById(R.id.suggestion_info);
suggestionIcon[i] = (ImageView) view.findViewById(R.id.suggestion_icon);
suggestionGrid.addView(view);
}
}
示例3: 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);
}
}
示例4: onCreateDialog
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int preselect = getArguments().getInt("preselect");
View view = View.inflate(getActivity(), R.layout.dialog_color_chooser, null);
mColors = initColors();
GridLayout gridLayout = (GridLayout) view.findViewById(R.id.grid);
for (int i = 0; i < mColors.length; i++) {
gridLayout.addView(getColorItemView(getActivity(), i, i == preselect));
}
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setTitle(R.string.color_chooser)
.setView(view)
.show();
return dialog;
}
示例5: 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;
}
示例6: createEditIcon
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
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, GridLayout.CENTER));
iconParams.topMargin = mVerticalMargin;
parent.addView(editorIcon, iconParams);
editorIcon.setOnClickListener(OptionSection.this);
return editorIcon;
}
示例7: onCreate
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_numbers);
getWindow().setStatusBarColor(Color.parseColor("#1C80CF"));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setBackgroundDrawable(getDrawable(R.color.blue));
LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
numberDao = literacyApplication.getDaoSession().getNumberDao();
audioDao = literacyApplication.getDaoSession().getAudioDao();
numberGridLayout = (GridLayout) findViewById(R.id.numberGridLayout);
List<Number> numbers = new CurriculumHelper(getApplication()).getAvailableNumbers(null);
Log.i(getClass().getName(), "numbers.size(): " + numbers.size());
for (final Number number : numbers) {
View numberView = LayoutInflater.from(this).inflate(R.layout.content_numbers_number_view, numberGridLayout, false);
TextView numberTextView = (TextView) numberView.findViewById(R.id.numberTextView);
if (!TextUtils.isEmpty(number.getSymbol())) {
numberTextView.setText(number.getSymbol());
} else {
numberTextView.setText(number.getValue().toString());
}
numberView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(getClass().getName(), "onClick");
Log.i(getClass().getName(), "number.getValue(): " + number.getValue());
Log.i(getClass().getName(), "number.getSymbol(): " + number.getSymbol());
Log.i(getClass().getName(), "number.getAllWords(): " + number.getWords());
if (!number.getWords().isEmpty()) {
for (Word numberWord : number.getWords()) {
Log.i(getClass().getName(), "numberWord.getText(): " + numberWord.getText());
}
}
playNumberSound(number);
EventTracker.reportNumberLearningEvent(getApplicationContext(), number.getValue());
Intent numberIntent = new Intent(getApplicationContext(), NumberActivity.class);
numberIntent.putExtra("number", number.getValue());
startActivity(numberIntent);
}
});
numberGridLayout.addView(numberView);
}
}
示例8: onCreate
import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_letters);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
LiteracyApplication literacyApplication = (LiteracyApplication) getApplicationContext();
letterDao = literacyApplication.getDaoSession().getLetterDao();
audioDao = literacyApplication.getDaoSession().getAudioDao();
letterGridLayout = (GridLayout) findViewById(R.id.letterGridLayout);
ContentProvider.initializeDb(this);
List<Allophone> allophones = ContentProvider.getAllAllophones();
Log.i(getClass().getName(), "allophones: " + allophones);
Log.i(getClass().getName(), "allophones.size(): " + allophones.size());
List<Letter> letters = new CurriculumHelper(getApplication()).getAvailableLetters(null);
Log.i(getClass().getName(), "letters.size(): " + letters.size());
for (final Letter letter : letters) {
View letterView = LayoutInflater.from(this).inflate(R.layout.content_letters_letter_view, letterGridLayout, false);
TextView letterTextView = (TextView) letterView.findViewById(R.id.letterTextView);
letterTextView.setText(letter.getText());
letterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(getClass().getName(), "onClick");
playLetterSound(letter);
EventTracker.reportLetterLearningEvent(getApplicationContext(), letter.getText());
Intent scrollingLetterIntent = new Intent(getApplicationContext(), ScrollingLetterActivity.class);
scrollingLetterIntent.putExtra("letter", letter.getText());
startActivity(scrollingLetterIntent);
}
});
letterGridLayout.addView(letterView);
}
}
示例9: 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;
}