當前位置: 首頁>>代碼示例>>Java>>正文


Java GridLayout.LayoutParams方法代碼示例

本文整理匯總了Java中android.support.v7.widget.GridLayout.LayoutParams方法的典型用法代碼示例。如果您正苦於以下問題:Java GridLayout.LayoutParams方法的具體用法?Java GridLayout.LayoutParams怎麽用?Java GridLayout.LayoutParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.GridLayout的用法示例。


在下文中一共展示了GridLayout.LayoutParams方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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);
    }
}
 
開發者ID:GavinAndre,項目名稱:MaterialWeather,代碼行數:23,代碼來源:MyAdapter.java

示例2: 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);
    }
}
 
開發者ID:emugabi,項目名稱:colorblocks,代碼行數:26,代碼來源:ColorPickerFragment.java

示例3: 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);
        }
    }
}
 
開發者ID:evant,項目名稱:PokeMVVM,代碼行數:20,代碼來源:TableCardLayout.java

示例4: 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);
}
 
開發者ID:Eason90,項目名稱:GridBuilder,代碼行數:22,代碼來源:GridBuilder.java

示例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;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:24,代碼來源:PaymentRequestSection.java

示例6: 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);
    }
}
 
開發者ID:dimagi,項目名稱:commcare-android,代碼行數:19,代碼來源:EntityViewTile.java

示例7: 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);
}
 
開發者ID:dimagi,項目名稱:commcare-android,代碼行數:22,代碼來源:EntityViewTile.java

示例8: 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);
            }
        }
    });
}
 
開發者ID:FreeSunny,項目名稱:Amazing,代碼行數:31,代碼來源:Sudoku.java

示例9: onCreateView

import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    ArrayList<Week> weeks = new Gson().fromJson(getArguments().getString(BUNDLE_WEEKS, ""), new TypeToken<ArrayList<Week>>() {}.getType());

    View view = inflater.inflate(R.layout.activity_main_home_fragment, container, false);
    ButterKnife.bind(this, view);

    SimpleDateFormat format = TimeUtils.createLongDateFormat();
    Calendar cal = Calendar.getInstance();

    date.setText(WordUtils.capitalize(format.format(new Date())));
    week.setText(String.format("Semaine %d", cal.get(Calendar.WEEK_OF_YEAR)));

    ArrayList<WrapperEventWeek> wrappers = WeekManager.getNextEvents(weeks, 1);

    for (WrapperEventWeek wrap : wrappers)
    {
        CardView card = new CardView(getContext());

        EventView eventView = new EventView(getContext(), EventView.EventViewType.CONDENSED);

        eventView.setData(wrap.getEvent(), wrap.getWeek());
        card.addView(eventView);

        GridLayout.LayoutParams params = new GridLayout.LayoutParams();
        params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
        params.setGravity(Gravity.FILL_VERTICAL);
        int margin = UIUtils.dp(getContext(), 10);
        params.setMargins(margin, margin, margin, margin);
        card.setLayoutParams(params);

        daysContainer.addView(card);
    }

    return view;
}
 
開發者ID:natinusala,項目名稱:openedt,代碼行數:38,代碼來源:MainActivity.java

示例10: getColorItemView

import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
private View getColorItemView(final Context context, int position, boolean isSelect) {
    int color = mColors[position];
    int widthImageCheckView = Utils.convertDensityPix(context, 24);
    int widthColorView = Utils.convertDensityPix(context, 56);
    int widthMargin = Utils.convertDensityPix(context, 4);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.ic_done_white_24dp);

    FrameLayout.LayoutParams ivParams = new FrameLayout.LayoutParams(widthImageCheckView, widthImageCheckView);
    ivParams.gravity = Gravity.CENTER;
    imageView.setLayoutParams(ivParams);
    imageView.setVisibility(isSelect ? View.VISIBLE : View.INVISIBLE);

    FrameLayout frameLayout = new FrameLayout(context);
    GridLayout.LayoutParams params = new GridLayout.LayoutParams(new FrameLayout.LayoutParams(widthColorView, widthColorView));
    params.setGravity(Gravity.CENTER);
    params.setMargins(widthMargin, widthMargin, widthMargin, widthMargin);
    frameLayout.setLayoutParams(params);

    setBackgroundSelector(frameLayout, color);

    frameLayout.addView(imageView);
    frameLayout.setOnClickListener(this);
    frameLayout.setTag(position);
    return frameLayout;
}
 
開發者ID:maoruibin,項目名稱:AppPlus,代碼行數:28,代碼來源:ColorChooseDialog.java

示例11: 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;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:15,代碼來源:PaymentRequestSection.java

示例12: getLayoutParamsForField

import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
private GridLayout.LayoutParams getLayoutParamsForField(GridCoordinate coordinateData) {
    Spec columnSpec = GridLayout.spec(coordinateData.getX(), coordinateData.getWidth());
    Spec rowSpec = GridLayout.spec(coordinateData.getY(), coordinateData.getHeight());

    GridLayout.LayoutParams gridParams = new GridLayout.LayoutParams(rowSpec, columnSpec);
    gridParams.width = (int)Math.ceil(cellWidth * coordinateData.getWidth());
    gridParams.height = (int)Math.ceil(cellHeight * coordinateData.getHeight());

    return gridParams;
}
 
開發者ID:dimagi,項目名稱:commcare-android,代碼行數:11,代碼來源:EntityViewTile.java

示例13: addItem

import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
/**
 * 向GridLayout容器中添加Grid元素
 *
 * @param gridItem Grid元素
 */
private GridBuilder addItem(GridItem gridItem) {
    View itemLayout = null;
    if (null != mOnViewCreateCallBack) {
        itemLayout = mOnViewCreateCallBack.onViewCreate(mLayoutInflater, null == mGridViewHolder
                ? null : mGridViewHolder.getConvertView(), gridItem);
    }

    if (null == itemLayout) {
        return this;
    }

    GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
    // 優先根據預先取得的width/height設置,但不影響跨列/行數
    layoutParams.width = (gridItem.getWidth() > 0 ? gridItem.getWidth() : gridItem.getColumnSpec() * mBaseWidth)
            + ((gridItem.getColumnSpec() > 1 && gridItem.getWidth() <= 0 ? mHorizontalMargin * (gridItem.getColumnSpec() - 1) : 0));
    layoutParams.height = (gridItem.getHeight() > 0 ? gridItem.getHeight() : gridItem.getRowSpec() * mBaseHeight)
            + ((gridItem.getRowSpec() > 1 && gridItem.getWidth() <= 0 ? mVerticalMargin * (gridItem.getRowSpec() - 1) : 0));

    if (gridItem.getWidth() <= 0) {
        gridItem.setWidth(layoutParams.width);
    }
    if (gridItem.getHeight() <= 0) {
        gridItem.setHeight(layoutParams.height);
    }

    layoutParams.rowSpec = GridLayout.spec(gridItem.getRow(), gridItem.getRowSpec());
    layoutParams.columnSpec = GridLayout.spec(gridItem.getColumn(), gridItem.getColumnSpec());

    // 設置每個item間距,最外層間距也需要設置(因為需要體現邊緣item的scale效果)
    if (gridItem.getRow() > 0) {
        layoutParams.topMargin = mVerticalMargin;
    }

    if (gridItem.getColumn() > 0) {
        layoutParams.leftMargin = mHorizontalMargin;
    }

    itemLayout.setLayoutParams(layoutParams);
    itemLayout.setFocusable(true);
    itemLayout.setClickable(true);
    itemLayout.setOnFocusChangeListener(this);
    itemLayout.setOnClickListener(this);
    itemLayout.setOnKeyListener(mOnKeyListener);
    itemLayout.setSoundEffectsEnabled(false);

    if (mGridLayout.getChildCount() == 0 && gridItem == mGridItemList.get(0)) {
        itemLayout.setTag(GridItem.TAG_FIRST_ITEM);
    }
    this.mGridLayout.addView(itemLayout);

    return this;
}
 
開發者ID:Eason90,項目名稱:GridBuilder,代碼行數:58,代碼來源:GridBuilder.java

示例14: onGlobalLayout

import android.support.v7.widget.GridLayout; //導入方法依賴的package包/類
@Override
public void onGlobalLayout() {

    // If stretchColumns/stretchRows are true, adjust width/height of all children to fill up the entire available space.
    int measuredWidth = lastMeasuredWidth;
    int measuredHeight = lastMeasuredHeight;

    if (stretchColumns)
        measuredWidth = getMeasuredWidth();
    if (stretchRows)
        measuredHeight = getMeasuredHeight();

    if (measuredWidth != lastMeasuredWidth || measuredHeight != lastMeasuredHeight) {
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            GridLayout.LayoutParams params = (GridLayout.LayoutParams) child.getLayoutParams();

            // Apply spacing to child's margin if it does not represent an outer border of the GridLayout.
            // Works only if each child spans one cell and its column and row numbers have not been set manually.
            if (horizontalSpacing > 0) {
                if (getOrientation() == HORIZONTAL) {
                    if (i % getColumnCount() != 0)  // Omit child on left border.
                        params.leftMargin = horizontalSpacing / 2;
                    if ((i + 1) % getColumnCount() != 0)  // Omit child on right border.
                        params.rightMargin = horizontalSpacing / 2;
                } else {
                    if ((i / getRowCount()) % getColumnCount() != 0)  // Omit child on left border.
                        params.leftMargin = horizontalSpacing / 2;
                    if ((i / getRowCount() + 1) % getColumnCount() != 0)  // Omit child on right border.
                        params.rightMargin = horizontalSpacing / 2;
                }
            }
            if (verticalSpacing > 0) {
                if (getOrientation() == HORIZONTAL) {
                    if ((i / getColumnCount()) % getRowCount() != 0)  // Omit child on top border.
                        params.topMargin = verticalSpacing / 2;
                    if ((i / getColumnCount() + 1) % getRowCount() != 0)  // Omit child on bottom border.
                        params.bottomMargin = verticalSpacing / 2;
                } else {
                    if (i % getRowCount() != 0)  // Omit child on top border.
                        params.topMargin = verticalSpacing / 2;
                    if ((i + 1) % getRowCount() != 0)  // Omit child on bottom border.
                        params.bottomMargin = verticalSpacing / 2;
                }
            }

            if (stretchColumns)
                params.width = (measuredWidth / getColumnCount()) - Math.max(0, params.rightMargin) - Math.max(0, params.leftMargin);
            if (stretchRows)
                params.height = (measuredHeight / getRowCount()) - Math.max(0, params.topMargin) - Math.max(0, params.bottomMargin);

            child.setLayoutParams(params);
        }

        if (stretchColumns)
            lastMeasuredWidth = measuredWidth;
        if (stretchRows)
            lastMeasuredHeight = measuredHeight;
    }
}
 
開發者ID:jrieke,項目名稱:ioiometer,代碼行數:61,代碼來源:MyGridLayout.java

示例15: update

import android.support.v7.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);
    }
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:62,代碼來源:PaymentRequestSection.java


注:本文中的android.support.v7.widget.GridLayout.LayoutParams方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。