android.widget.GridView.setPadding()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中android.widget.GridView.setPadding()方法的一些代码示例,展示了GridView.setPadding()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridView.setPadding()方法的具体详情如下:
包路径:android.widget.GridView
类名称:GridView
方法名:setPadding

GridView.setPadding介绍

暂无

代码示例

代码示例来源:origin: Flipboard/bottomsheet

public void setTitle(String title) {
  this.title = title;
  if (!TextUtils.isEmpty(title)) {
    titleView.setText(title);
  } else {
    titleView.setVisibility(GONE);
    // Add some padding to the top to account for the missing title
    tileGrid.setPadding(tileGrid.getPaddingLeft(), originalGridPaddingTop + spacing, tileGrid.getPaddingRight(), tileGrid.getPaddingBottom());
  }
}

代码示例来源:origin: Flipboard/bottomsheet

tileGrid.setVerticalSpacing(spacing);
tileGrid.setHorizontalSpacing(spacing);
tileGrid.setPadding(spacing, 0, spacing, 0);

代码示例来源:origin: stackoverflow.com

// Convert DIPs to pixels
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mSizePx = (int) Math.floor(SIZE_DIP * metrics.scaledDensity);
mSpacingPx = (int) Math.floor(SPACING_DIP * metrics.scaledDensity);

GridView gridview = (GridView) findViewById(R.id.gridview);
// Find out the extra space gridview uses for selector on its sides.
Rect p = new Rect();
gridview.getSelector().getPadding(p);
int selectorPadding = p.left + p.right;

// Determine the number of columns we can fit, given screen width,
// thumbnail width, and spacing between thumbnails.
int numColumns = (int) Math.floor(1f * (metrics.widthPixels - selectorPadding + mSpacingPx)
    / (mSizePx + mSpacingPx));

int contentWidth = numColumns * mSizePx; // Width of items
contentWidth += (numColumns - 1) * mSpacingPx; // Plus spaces between items
contentWidth += selectorPadding; // Plus extra space for selector on sides

// Now calculate amount of left and right margin so the grid gets
// centered. This is what we
// unfortunately cannot do with layout_width="wrap_content"
// and layout_gravity="center_horizontal"
int slack = metrics.widthPixels - contentWidth;

gridview.setNumColumns(numColumns);
gridview.setPadding(slack / 2, slack / 2, slack / 2, slack / 2);

代码示例来源:origin: Kennyc1012/BottomSheet

private void initUi(){
  boolean hasTitle = !TextUtils.isEmpty(builder.title);
  if (hasTitle) {
    title.setText(builder.title);
  } else {
    title.setVisibility(View.GONE);
  }
  if (!builder.isGrid) {
    int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_menu_list_padding);
    gridView.setPadding(0, hasTitle ? 0 : padding, 0, padding);
  }
  gridView.setNumColumns(getNumberColumns());
}

代码示例来源:origin: Kennyc1012/BottomSheetMenu

private void initUi(){
  boolean hasTitle = !TextUtils.isEmpty(builder.title);
  if (hasTitle) {
    title.setText(builder.title);
  } else {
    title.setVisibility(View.GONE);
  }
  if (!builder.isGrid) {
    int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_menu_list_padding);
    gridView.setPadding(0, hasTitle ? 0 : padding, 0, padding);
  }
  gridView.setNumColumns(getNumberColumns());
}

代码示例来源:origin: freedom10086/Ruisi

WaterHolder(View itemView) {
    super(itemView);
    GridView g = (GridView) itemView;
    int p12 = DimenUtils.dip2px(context, 12);
    g.setVerticalSpacing(p12);
    g.setHorizontalSpacing(p12);
    WindowManager wm = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
    Point point = new Point();
    wm.getDefaultDisplay().getSize(point);
    int width = point.x;
    int itemWidth = (width - (p12 * 9)) / 8;
    g.setLayoutParams(new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT,
        (ds.size() <= 8 ? itemWidth + p12 * 2 : itemWidth * 2 + p12 * 3)));
    g.setPadding(p12, p12, p12, p12);
    g.setNumColumns(8);
    g.setAdapter(new WaterBAdapter(itemWidth));
    g.setOnItemClickListener((parent, view, position, id) -> {
      WaterData d = ds.get(position);
      UserDetailActivity.open(context, d.name, d.imgSrc, d.uid);
    });
    g.setOnItemLongClickListener((parent, view, position, id) -> {
      WaterData d = ds.get(position);
      Toast.makeText(context, d.name + "\n帖子数:" + d.num, Toast.LENGTH_SHORT).show();
      return true;
    });
  }
}

代码示例来源:origin: marzika/Snapprefs

addFilters();
gridView = (GridView) view.findViewById(R.id.filter_grid);
gridView.setPadding(0,0,0,0);
mAdapter = new FilterAdapter();
gridView.setAdapter(mAdapter);

代码示例来源:origin: michael-rapp/AndroidBottomSheet

/**
 * Shows the grid view, which is used to show the bottom sheet's items.
 */
private void showGridView() {
  gridView = contentContainer.findViewById(R.id.bottom_sheet_grid_view);
  if (gridView != null) {
    contentContainer.setVisibility(View.VISIBLE);
    if (getStyle() == Style.GRID) {
      int horizontalPadding = getContext().getResources()
          .getDimensionPixelSize(R.dimen.bottom_sheet_grid_item_horizontal_padding);
      int paddingBottom = getContext().getResources()
          .getDimensionPixelSize(R.dimen.bottom_sheet_grid_padding_bottom);
      gridView.setPadding(horizontalPadding, 0, horizontalPadding, paddingBottom);
      gridView.setNumColumns(GridView.AUTO_FIT);
      gridView.setColumnWidth(getContext().getResources()
          .getDimensionPixelSize(R.dimen.bottom_sheet_grid_item_size));
    } else {
      int paddingBottom = getContext().getResources()
          .getDimensionPixelSize(R.dimen.bottom_sheet_list_padding_bottom);
      gridView.setPadding(0, 0, 0, paddingBottom);
      gridView.setNumColumns(getStyle() == Style.LIST_COLUMNS &&
          (getDeviceType(getContext()) == DisplayUtil.DeviceType.TABLET ||
              getOrientation(getContext()) == DisplayUtil.Orientation.LANDSCAPE) ?
          2 : 1);
    }
    gridView.setOnItemClickListener(createItemClickListener());
    gridView.setOnItemLongClickListener(createItemLongClickListener());
    gridView.setAdapter(adapter);
  }
}

代码示例来源:origin: werbhelius/Werb

/**
 * 创建显示表情的GridView
 */
private GridView createEmotionGridView(List<String> emotionNames, int gvWidth, int padding, int itemWidth, int gvHeight) {
  // 创建GridView
  GridView gv = new GridView(context);
  gv.setBackgroundResource(R.color.bg_gray);
  gv.setSelector(R.color.transparent);
  gv.setNumColumns(7);
  gv.setPadding(padding, padding, padding, padding);
  gv.setHorizontalSpacing(padding);
  gv.setVerticalSpacing(padding);
  ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(gvWidth, gvHeight);
  gv.setLayoutParams(params);
  // 给GridView设置表情图片
  EmotionGvAdapter adapter = new EmotionGvAdapter(context, emotionNames, itemWidth);
  gv.setAdapter(adapter);
  gv.setOnItemClickListener(this);
  return gv;
}

代码示例来源:origin: freedom10086/Ruisi

private void init() {
  String[] colors = mContext.getResources().getStringArray(R.array.color_list);
  for (int i = 0; i < colors.length; i++) {
    if (colorDatas == null) {
      colorDatas = new String[colors.length][2];
    }
    colorDatas[i][0] = colors[i].split(",")[0];
    colorDatas[i][1] = colors[i].split(",")[1];
  }
  gridView = new GridView(mContext);
  gridView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  gridView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
  gridView.setNumColumns(8);
  gridView.setPadding(DimenUtils.dip2px(mContext, 8), DimenUtils.dip2px(mContext, 12), DimenUtils.dip2px(mContext, 8), DimenUtils.dip2px(mContext, 12));
  gridView.setGravity(Gravity.CENTER);
  gridView.setHorizontalSpacing(DimenUtils.dip2px(mContext, 4));
  gridView.setVerticalSpacing(DimenUtils.dip2px(mContext, 12));
  gridView.setOnItemClickListener(this);
  setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
  setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
  setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.rec_solid_primary_bg));
  setFocusable(true);
  setContentView(gridView);
  adapter = new MyAdapter();
  gridView.setAdapter(adapter);
}

代码示例来源:origin: Meiqia/MeiqiaSDK-Android

GridView gridView = new GridView(getContext());
gridView.setPadding(edge, edge, edge, edge);
gridView.setNumColumns(EMOTION_COLUMN);
gridView.setVerticalSpacing(edge);

代码示例来源:origin: stackoverflow.com

gridView.setColumnWidth(columnWidth);
gridView.setStretchMode(GridView.NO_STRETCH);
gridView.setPadding((int) padding, (int) padding, (int) padding,
    (int) padding);
gridView.setHorizontalSpacing((int) padding);

代码示例来源:origin: stackoverflow.com

gridView.setColumnWidth(columnWidth);
gridView.setStretchMode(GridView.NO_STRETCH);
gridView.setPadding((int) padding, (int) padding, (int) padding,(int) padding);
gridView.setHorizontalSpacing((int) padding);
gridView.setVerticalSpacing((int) padding);

代码示例来源:origin: AriesHoo/UIWidget

mGvContainer.setVerticalSpacing(mVerticalSpacing);
mGvContainer.setAdapter(mAdapter);
mGvContainer.setPadding(mGridPadding, mGridPadding, mGridPadding, mGridPadding);
setViewBackground(mGvContainer, mGridBackground);
setViewBackground(mTvTitle, mGridBackground);

代码示例来源:origin: marzika/Snapprefs

@Override
  protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
    if (!once){
      View colorPickerView = (View) getObjectField(param.thisObject, "j");
      outerOptionsLayout = new RelativeLayout(HookMethods.SnapContext);
      final GridView innerOptionsView = new GridView(HookMethods.SnapContext);
      innerOptionsView.setAdapter(new OptionsAdapter(HookMethods.SnapContext, mResources));
      innerOptionsView.setNumColumns(5);
      innerOptionsView.setHorizontalSpacing(px(2.0f));
      innerOptionsView.setVerticalSpacing(px(5.0f));
      innerOptionsView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
      innerOptionsView.setPadding(0,px(7.5f), px(1.0f), px(7.5f));
      final RelativeLayout.LayoutParams outerOptionsLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
      outerOptionsLayoutParams.leftMargin = px(75.0f);
      outerOptionsLayoutParams.rightMargin = px(25.0f);
      outerOptionsLayout.setVisibility(View.VISIBLE);
      outerOptionsLayout.setBackgroundDrawable(mResources.getDrawable(R.drawable.drawingbackground));
      outerOptionsLayout.addView(innerOptionsView, GridLayout.LayoutParams.MATCH_PARENT, GridLayout.LayoutParams.MATCH_PARENT);
      ((RelativeLayout)colorPickerView.getParent().getParent()).addView(outerOptionsLayout, outerOptionsLayoutParams);
      once = true;
    }
  }
});

代码示例来源:origin: shinezejian/emotionkeyboard

/**
 * 创建显示表情的GridView
 */
private GridView createEmotionGridView(List<String> emotionNames, int gvWidth, int padding, int itemWidth, int gvHeight) {
  // 创建GridView
  GridView gv = new GridView(getActivity());
  //设置点击背景透明
  gv.setSelector(android.R.color.transparent);
  //设置7列
  gv.setNumColumns(7);
  gv.setPadding(padding, padding, padding, padding);
  gv.setHorizontalSpacing(padding);
  gv.setVerticalSpacing(padding * 2);
  //设置GridView的宽高
  ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(gvWidth, gvHeight);
  gv.setLayoutParams(params);
  // 给GridView设置表情图片
  EmotionGridViewAdapter adapter = new EmotionGridViewAdapter(getActivity(), emotionNames, itemWidth,emotion_map_type);
  gv.setAdapter(adapter);
  //设置全局点击事件
  gv.setOnItemClickListener(GlobalOnItemClickManagerUtils.getInstance(getActivity()).getOnItemClickListener(emotion_map_type));
  return gv;
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

gridview.setHorizontalSpacing(40);
gridview.setVerticalSpacing(40);
gridview.setPadding(20, 20, 20, 0);
gridview.setFastScrollEnabled(true);
gridview.setColumnWidth(iconSize);

代码示例来源:origin: chengzichen/KrGallery

listView.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4),
    AndroidUtilities.dp(4));
listView.setClipToPadding(false);

代码示例来源:origin: marzika/Snapprefs

innerOptionsView.setVerticalSpacing(px(5.0f));
innerOptionsView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
innerOptionsView.setPadding(0, px(7.5f), px(1.0f), px(7.5f));
final RelativeLayout.LayoutParams outerOptionsLayoutParams =
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

相关文章

GridView类方法