本文整理匯總了Java中android.support.v7.widget.GridLayout類的典型用法代碼示例。如果您正苦於以下問題:Java GridLayout類的具體用法?Java GridLayout怎麽用?Java GridLayout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GridLayout類屬於android.support.v7.widget包,在下文中一共展示了GridLayout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
@Override
public void run() {
switch (mBackspaceLocation) {
case LOCATION_HEADER:
break;
case LOCATION_FOOTER:
((ViewGroup) mHeader).removeView(mBackspace);
// The row of the cell in which the backspace key should go.
// This specifies the row index, which spans one increment,
// and indicates the cell should be filled along the row
// (horizontal) axis.
final GridLayout.Spec rowSpec = GridLayout.spec(
mNumberPad.getRowCount() - 1, GridLayout.FILL);
// The column of the cell in which the backspace key should go.
// This specifies the column index, which spans one increment,
// and indicates the cell should be filled along the column
// (vertical) axis.
final GridLayout.Spec columnSpec = GridLayout.spec(
mNumberPad.getColumnCount() - 1, GridLayout.FILL);
mNumberPad.addView(mBackspace, new GridLayout.LayoutParams(
rowSpec, columnSpec));
break;
}
}
示例2: 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);
}
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: setData
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
public void setData(Collection<Row> rows) {
gridLayout.removeViews(1, gridLayout.getChildCount() - 1);
for (Row row : rows) {
{
TextView nameView = new TextView(getContext());
TextViewCompat.setTextAppearance(nameView, android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1);
nameView.setText(row.name());
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
gridLayout.addView(nameView, params);
}
{
TextView valueView = new TextView(getContext());
TextViewCompat.setTextAppearance(valueView, android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1);
valueView.setText(row.value());
gridLayout.addView(valueView);
}
}
}
示例6: onPostExecute
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
@Override
protected void onPostExecute(TimeSearchResult timeSearchResult) {
if (timeSearchResult == null) {
Log.i(TAG, "onPostExecute: 失敗 查詢時效 獲得空結果");
return;
}
Log.d(TAG, "onPostExecute: 成功 查詢時效 獲得數量: " + timeSearchResult.getEntries().size());
GridLayout gridLayout = mActivity.getGridLayout();
gridLayout.removeAllViews();
gridLayout.setColumnCount(2);
for (TimeSearchResult.Entry entry : timeSearchResult.getEntries()) {
String companyName = entry.getCompanyName();
String time = entry.getTime();
HttpUrl logoUrl = HttpUrl.parse(entry.getCompanyLogoUrl());
CardView card =
(CardView) mActivity.getLayoutInflater().inflate(R.layout.card_time, mActivity.getGridLayout(), false);
ImageView logo = (ImageView) card.findViewById(R.id.logo);
TextView companyNameText = (TextView) card.findViewById(R.id.company_name);
TextView timeText = (TextView) card.findViewById(R.id.time);
fetcher.DownloadImage(this, logoUrl, logo);
companyNameText.setText(companyName.trim());
timeText.setText(time.trim());
mActivity.getGridLayout().addView(card);
}
}
示例7: addReflectionImageView
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
/**
* 將倒影布局添加到GridLayout容器中
*/
private void addReflectionImageView() {
mReflectionImageView = new ImageView(mContext);
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.width = mColumnCount * mBaseWidth
+ ((mColumnCount > 1 ? mHorizontalMargin * (mColumnCount - 1) : 0));
layoutParams.height = mBaseHeight;
layoutParams.rowSpec = GridLayout.spec(mRowCount - 1, 1);
layoutParams.columnSpec = GridLayout.spec(0, mColumnCount);
mReflectionImageView.setLayoutParams(layoutParams);
mReflectionImageView.setScaleType(ImageView.ScaleType.FIT_XY);
this.refreshReflection(0);
mGridLayout.addView(mReflectionImageView);
mReflectionImageView.setVisibility(mVisibility);
}
示例8: 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;
}
示例9: createMainSectionContent
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
@Override
protected void createMainSectionContent(LinearLayout mainSectionLayout) {
Context context = mainSectionLayout.getContext();
// Add a label that will be used to indicate that the total cart price has been updated.
addUpdateText(mainSectionLayout);
// The breakdown is represented by an end-aligned GridLayout that takes up only as much
// space as it needs. The GridLayout ensures a consistent margin between the columns.
mBreakdownLayout = new GridLayout(context);
mBreakdownLayout.setColumnCount(2);
LayoutParams breakdownParams =
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
breakdownParams.gravity = Gravity.END;
mainSectionLayout.addView(mBreakdownLayout, breakdownParams);
// Sets the summary right text view takes the same available space as the summary left
// text view.
LinearLayout.LayoutParams rightTextViewLayoutParams =
(LinearLayout.LayoutParams) getSummaryRightTextView().getLayoutParams();
rightTextViewLayoutParams.width = 0;
rightTextViewLayoutParams.weight = 1f;
}
示例10: 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;
}
示例11: addBuffersToView
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
private void addBuffersToView(Context context, int count, boolean isRow) {
for (int i = 0; i < count; i++) {
GridLayout.LayoutParams gridParams;
if (isRow) {
gridParams = new GridLayout.LayoutParams(GridLayout.spec(i), GridLayout.spec(0));
gridParams.width = 1;
gridParams.height = (int)cellHeight;
} else {
gridParams = new GridLayout.LayoutParams(GridLayout.spec(0), GridLayout.spec(i));
gridParams.width = (int)cellWidth;
gridParams.height = 1;
}
Space space = new Space(context);
space.setLayoutParams(gridParams);
this.addView(space, gridParams);
}
}
示例12: addFieldView
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
private void addFieldView(Context context, String form,
GridStyle style, GridCoordinate coordinateData, String fieldString,
String sortField, int index) {
if (coordinatesInvalid(coordinateData)) {
return;
}
ViewId uniqueId = ViewId.buildTableViewId(coordinateData.getX(), coordinateData.getY(), false);
GridLayout.LayoutParams gridParams = getLayoutParamsForField(coordinateData);
View view = getView(context, style, form, fieldString, uniqueId, sortField,
gridParams.width, gridParams.height);
if (!(view instanceof ImageView)) {
gridParams.height = LayoutParams.WRAP_CONTENT;
}
view.setLayoutParams(gridParams);
mFieldViews[index] = view;
this.addView(view, gridParams);
}
示例13: fillSensorsTextViews
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
private void fillSensorsTextViews(String source) {
ArrayList<InfoItem> infoItemArray = getData();
for (int i = 0; i < mLayoutData.getChildCount(); i++) {
InfoItem item = infoItemArray.get(i);
if (!item.getTitle().equals(source))
continue;
LinearLayout layout = (LinearLayout) mLayoutData.getChildAt(i);
GridLayout values = (GridLayout) layout.findViewById(R.id.gl_values);
for (int j = 0; j < item.size(); j++) {
TextView data = (TextView) values.getChildAt(j);
InfoColumn column = item.getColumns().get(j);
setValue(data, column);
}
}
}
示例14: updateView
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
private void updateView() {
removeAllViews();// remove all views
int size = urls != null ? urls.size() : 0;
int columnCount = getCol(size);
for (int i = 0; i < size; ++i) {
GridLayout.Spec row = GridLayout.spec(i / columnCount);
GridLayout.Spec col = GridLayout.spec(i % columnCount, 1.0f);
ImageView imageView = getImageView(i);
//由於寬(即列)已經定義權重比例 寬設置為0 保證均分
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(new ViewGroup.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT));
layoutParams.rowSpec = row;
layoutParams.columnSpec = col;
layoutParams.setMargins(margin, margin, margin, margin);
addView(imageView, layoutParams);
}
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ViewGroup.LayoutParams lp = getLayoutParams();
if (getHeight() > 0 && lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
lp.height = getHeight();
setLayoutParams(lp);
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}
示例15: onCreateDialog
import android.support.v7.widget.GridLayout; //導入依賴的package包/類
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View rootView = layoutInflater.inflate(R.layout.color_preference_items, null);
mColorGrid = (GridLayout) rootView.findViewById(R.id.color_grid);
mColorGrid.setColumnCount(mPreference.mNumColumns);
repopulateItems();
return new AlertDialog.Builder(getActivity())
.setView(rootView)
.create();
}