本文整理匯總了Java中android.widget.GridLayout.spec方法的典型用法代碼示例。如果您正苦於以下問題:Java GridLayout.spec方法的具體用法?Java GridLayout.spec怎麽用?Java GridLayout.spec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.GridLayout
的用法示例。
在下文中一共展示了GridLayout.spec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createOptionIcon
import android.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);
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;
}
示例2: generateColoredButtons
import android.widget.GridLayout; //導入方法依賴的package包/類
private void generateColoredButtons() {
for (int i=0; i<ROWS; i++) {
for (int j=0; j<COLUMNS; j++) {
int count = COLUMNS * i + j;
if (count > Constants.COLORS.length - 1) {
return;
}
Button b = new Button(this);
b.setBackgroundResource(R.drawable.round_button);
b.setBackgroundColor(getResources().getColor(Constants.COLORS[count]));
b.setTag(count);
b.setOnClickListener(this);
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.height = GridLayout.LayoutParams.WRAP_CONTENT;
params.width = GridLayout.LayoutParams.WRAP_CONTENT;
params.rowSpec = GridLayout.spec(i);
params.columnSpec = GridLayout.spec(j);
b.setLayoutParams(params);
mGrid.addView(b);
}
}
}
示例3: addTableHeader
import android.widget.GridLayout; //導入方法依賴的package包/類
private GridLayout addTableHeader( String... headers ) {
GridLayout gridLayout = new GridLayout( getContext() );
gridLayout.setBackgroundResource( R.color.grey_faint );
int rowNum = 0;
int columnNum = 0;
for ( String header : headers ) {
RobotoTextView headerText = new RobotoTextView( getContext() );
headerText.setTextAppearance( getContext(), R.style.CardKey );
headerText.setText( header );
Spec rowspecs = GridLayout.spec( rowNum, 1 );
Spec colspecs = GridLayout.spec( columnNum, 1 );
GridLayout.LayoutParams params = new GridLayout.LayoutParams( rowspecs, colspecs );
params.setGravity( Gravity.CENTER_HORIZONTAL );
params.setMargins( getContext().getResources().getDimensionPixelSize( R.dimen.column_padding ), 0, getContext().getResources().getDimensionPixelSize( R.dimen.column_padding ), 0 );
gridLayout.addView( headerText, params );
columnNum++;
}
return gridLayout;
}
示例4: addTableRow
import android.widget.GridLayout; //導入方法依賴的package包/類
private void addTableRow( GridLayout gridLayout, String... columns ) {
int rowNum = gridLayout.getRowCount();
int columnNum = 0;
for ( String column : columns ) {
RobotoTextView columnText = new RobotoTextView( getContext() );
columnText.setTextAppearance( getContext(), R.style.CardValue );
columnText.setText( column );
Spec rowspecs = GridLayout.spec( rowNum, 1 );
Spec colspecs = GridLayout.spec( columnNum, 1 );
GridLayout.LayoutParams params = new GridLayout.LayoutParams( rowspecs, colspecs );
params.setGravity( Gravity.CENTER_HORIZONTAL );
gridLayout.addView( columnText, params );
columnNum++;
}
}
示例5: createEditIcon
import android.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));
iconParams.topMargin = mVerticalMargin;
parent.addView(editorIcon, iconParams);
editorIcon.setOnClickListener(OptionSection.this);
return editorIcon;
}
示例6: layoutParamsFromGridPosition
import android.widget.GridLayout; //導入方法依賴的package包/類
private void layoutParamsFromGridPosition(GridPosition gridPosition, LayoutParams params){
int columnCount = getNewColumnCount();
params.setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
params.height = gridPosition.getHeight() - params.topMargin - params.bottomMargin;
params.width = gridPosition.getWidth() - params.leftMargin - params.rightMargin;
params.columnSpec = GridLayout.spec((int)(gridPosition.getPositionX()*columnCount),
columnCount/gridPosition.getInverseWidth());
params.rowSpec = GridLayout.spec((int)(gridPosition.getPositionY()*columnCount),
columnCount/gridPosition.getInverseHeight());
}
示例7: setAttributes
import android.widget.GridLayout; //導入方法依賴的package包/類
public void setAttributes(View view)
{
GridLayout viewParent = (GridLayout)view.getParent();
GridLayout.Spec spec = GridLayout.spec(getStart(), getSpan(), getAlignment(viewParent, layout_gravity, isHorizontal()));
GridLayout.LayoutParams params = (GridLayout.LayoutParams)view.getLayoutParams();
setSpec(params,spec);
}
示例8: initGridLayout
import android.widget.GridLayout; //導入方法依賴的package包/類
private void initGridLayout() {
gridLayout.removeAllViews();
int total = 12;
int column = 5;
int row = total / column;
gridLayout.setColumnCount(column);
gridLayout.setRowCount(row + 1);
for(int i =0, c = 0, r = 0; i < total; i++, c++)
{
if(c == column)
{
c = 0;
r++;
}
ImageView oImageView = new ImageView(this);
oImageView.setImageResource(R.mipmap.ic_launcher);
GridLayout.LayoutParams param =new GridLayout.LayoutParams();
param.height = GridLayout.LayoutParams.WRAP_CONTENT;
param.width = GridLayout.LayoutParams.WRAP_CONTENT;
param.rightMargin = 5;
param.topMargin = 5;
param.setGravity(Gravity.CENTER);
param.columnSpec = GridLayout.spec(c);
param.rowSpec = GridLayout.spec(r);
oImageView.setLayoutParams (param);
gridLayout.addView(oImageView);
}
}
示例9: addHeader
import android.widget.GridLayout; //導入方法依賴的package包/類
void addHeader(String name, IntRef currentRow, int numColumns, LayoutInflater inflater) {
View header = inflater.inflate(R.layout.grid_header, null);
//each header should take up one row and all available columns
GridLayout.LayoutParams params = new GridLayout.LayoutParams(GridLayout.spec(currentRow.value, 1), GridLayout.spec(0, numColumns));
params.width = gridLayout.getWidth();
header.setLayoutParams(params);
gridLayout.addView(header);
((TextView) header.findViewById(R.id.header_text)).setText(name);
currentRow.value += 1; //point currentRow to row where next views should be added
}
示例10: addGridItems
import android.widget.GridLayout; //導入方法依賴的package包/類
void addGridItems(IntRef currentRow, int numColumns, LayoutInflater inflater, Resources res, int size, MetricsManager.Metrics[] metricsToAdd) {
//keeps track of the column we are adding to
int col = -1; //start col at -1 so it becomes 0 during first iteration of for loop
for (MetricsManager.Metrics metric : metricsToAdd) {
col += 1;
if (col >= numColumns) {
col = 0;
currentRow.value += 1;
}
MetricSelector item = metricSelectors.get(metric);
if (item != null) {
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.width = size;
params.height = size;
params.columnSpec = GridLayout.spec(col);
params.rowSpec = GridLayout.spec(currentRow.value);
item.setLayoutParams(params);
item.setOnClickListener(this);
gridLayout.addView(item);
} else {
Log.e(LOG_TAG, "Unknown MetricSelector item for Metric: " + metric.toString());
}
}
currentRow.value += 1; //point currentRow to row where next views should be added
}
示例11: updateUI
import android.widget.GridLayout; //導入方法依賴的package包/類
private void updateUI() {
mGridLayout.removeAllViews();
mGridLayout.setRowCount(mAdapter.getRowCount());
mGridLayout.setOrientation(GridLayout.VERTICAL);
int count = mAdapter.getCount();
int minWidth = mAdapter.getMinWidth();
int minHeight = mAdapter.getMinHeight();
int margin = mAdapter.getMargin();
for (int position = 0; position < count; position++) {
int widthRatio = mAdapter.getWidthRatio(position);
int heightRatio = mAdapter.getHeightRatio(position);
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.width = minWidth * widthRatio;
if (widthRatio > 1) {
params.width += (margin * (widthRatio - 1) * 2);
}
params.height = minHeight * heightRatio;
if (heightRatio > 1) {
params.height += (margin * (heightRatio - 1) * 2);
}
params.rowSpec = GridLayout.spec(Integer.MIN_VALUE, heightRatio);
params.columnSpec = GridLayout.spec(Integer.MIN_VALUE, widthRatio);
params.setMargins(margin, margin, margin, margin);
View view = mAdapter.getView(position, null, null);
view.setLayoutParams(params);
mGridLayout.addView(view);
view.setFocusable(true);
view.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
mAnimationProvider.applyAnimation(hasFocus, v, mImageViewCenter,
mImageViewBorder, mImageViewShadow);
}
});
}
}
示例12: update
import android.widget.GridLayout; //導入方法依賴的package包/類
/**
* Updates the total and how it's broken down.
*
* @param cart The shopping cart contents and the total.
*/
public void update(ShoppingCart cart) {
Context context = mBreakdownLayout.getContext();
CharSequence totalPrice = createValueString(
cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true);
// Show the updated text view if the total changed.
showUpdateIfTextChanged(totalPrice);
// Update the summary to display information about the total.
setSummaryText(cart.getTotal().getLabel(), totalPrice);
mBreakdownLayout.removeAllViews();
if (cart.getContents() == null) return;
int maximumDescriptionWidthPx =
((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3;
// Update the breakdown, using one row per {@link LineItem}.
int numItems = cart.getContents().size();
mBreakdownLayout.setRowCount(numItems);
for (int i = 0; i < numItems; i++) {
LineItem item = cart.getContents().get(i);
TextView description = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending()
? R.style.PaymentsUiSectionPendingTextEndAligned
: R.style.PaymentsUiSectionDescriptiveTextEndAligned);
description.setText(item.getLabel());
description.setEllipsize(TruncateAt.END);
description.setMaxLines(2);
if (maximumDescriptionWidthPx > 0) {
description.setMaxWidth(maximumDescriptionWidthPx);
}
TextView amount = new TextView(context);
ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending()
? R.style.PaymentsUiSectionPendingTextEndAligned
: R.style.PaymentsUiSectionDescriptiveTextEndAligned);
amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));
// Each item is represented by a row in the GridLayout.
GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(0, 1, GridLayout.END));
GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
GridLayout.spec(i, 1, GridLayout.END),
GridLayout.spec(1, 1, GridLayout.END));
ApiCompatibilityUtils.setMarginStart(amountParams,
context.getResources().getDimensionPixelSize(
R.dimen.payments_section_descriptive_item_spacing));
mBreakdownLayout.addView(description, descriptionParams);
mBreakdownLayout.addView(amount, amountParams);
}
}
示例13: createLabel
import android.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)));
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;
}
示例14: getAppLauncherLayoutParams
import android.widget.GridLayout; //導入方法依賴的package包/類
@NonNull
private GridLayout.LayoutParams getAppLauncherLayoutParams(GridLayout grid, AppLauncher app) {
GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
int w = getLauncherWidth(app);
int h = getLauncherHeight(app);
if (w>0 || h>0) {
//float sw = getResources().getDimension(R.dimen.launcher_width);
float sw = mStyle.getLauncherSize();
//float sh = getResources().getDimension(R.dimen.launcher_height);
//int width = (int)(sw + 20) * mColumns;
float cellwidth = sw * 1f;
float cellheight = cellwidth + 5; // ~square cells
int wcells = (int) Math.ceil(w / cellwidth);
if (wcells > 1) {
int start = GridLayout.UNDEFINED;
if (wcells > grid.getColumnCount()) {
wcells = grid.getColumnCount();
}
// if (wcells > 1) start = 0;
lp.columnSpec = GridLayout.spec(start, wcells, GridLayout.FILL);
//Log.d("widcol", "w=" + w + " wcells=" + wcells + " start=" + start + " cellwidth=" + cellwidth + " r=" + cellwidth * wcells);
} else {
lp.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1, GridLayout.FILL);
}
int hcells = (int) Math.ceil(h / cellheight);
if (hcells > 1) {
lp.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, hcells, GridLayout.FILL);
} else {
lp.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, 1, GridLayout.FILL);
}
final AppWidgetHostView appwid = mLoadedWidgets.get(app.getActivityName());
if (appwid != null) {
//appwid.updateAppWidgetSize(null, (int) sw, (int) sh, (int) (cellwidth * wcells), (int) (cellheight * hcells));
//magic numbers to properly expand widgets...
final int wDp = pxToDip(cellwidth*wcells);
final int hDp = pxToDip(cellheight*hcells*4/3);
lp.width = (int)(cellwidth*wcells*1.1);
lp.height = (int)(cellheight*hcells*4/3);
//Log.d("widcol2", "w=" + w + " wcells=" + wcells + " cellwidth=" + cellwidth + " r=" + cellwidth * wcells);
//Log.d("widcol2", "h=" + w + " hcells=" + hcells + " cellheight=" + cellheight + " r=" + cellheight * hcells);
appwid.postDelayed(new Runnable() {
@Override
public void run() {
appwid.updateAppWidgetSize(null, wDp, hDp, wDp, hDp);
if (appwid.getParent()!=null) {
appwid.getParent().requestLayout();
}
appwid.requestLayout();
}
}, 1000);
}
}
return lp;
}
示例15: onCreateView
import android.widget.GridLayout; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int index = getArguments().getInt("INDEX");
View v = inflater.inflate(R.layout.view_matrix_frag, container, false);
CardView cardView = (CardView) v.findViewById(R.id.DynamicCardView);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");
cardView.setCardElevation(Integer.parseInt(string));
cardView.setCardBackgroundColor(Color.parseColor(string2));
CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
GridLayout gridLayout = new GridLayout(getContext());
gridLayout.setRowCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow());
gridLayout.setColumnCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol());
for (int i = 0; i < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(); i++) {
for (int j = 0; j < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(); j++) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.CENTER);
textView.setText(SafeSubString(GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetElementof(i, j)), getLength()));
textView.setWidth(CalculatedWidth(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol()));
textView.setTextSize(SizeReturner(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(), ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(),
PreferenceManager.getDefaultSharedPreferences(getContext()).
getBoolean("EXTRA_SMALL_FONT", false)));
textView.setHeight(CalculatedHeight(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow()));
GridLayout.Spec Row = GridLayout.spec(i, 1);
GridLayout.Spec Col = GridLayout.spec(j, 1);
GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
gridLayout.addView(textView, params);
}
}
gridLayout.setLayoutParams(params1);
cardView.addView(gridLayout);
// Inflate the layout for this fragment
return v;
}