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

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

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

GridView.setNumColumns介绍

暂无

代码示例

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

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  int width = MeasureSpec.getSize(widthMeasureSpec);
  float density = getResources().getDisplayMetrics().density;
  final int numColumns = (int) (width / (columnWidthDp * density));
  thumbnailSize = Math.round((width - ((numColumns - 1) * spacing)) / 3.0f);
  tileGrid.setNumColumns(numColumns);
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

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

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  if (menuType == GRID) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    final float density = getResources().getDisplayMetrics().density;
    ((GridView) absListView).setNumColumns((int) (width / (columnWidthDp * density)));
  }
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

代码示例来源:origin: TonicArtos/StickyGridHeaders

@Override
public void setNumColumns(int numColumns) {
  super.setNumColumns(numColumns);
  mNumColumnsSet = true;
  this.mNumColumns = numColumns;
  if (numColumns != AUTO_FIT && mAdapter != null) {
    mAdapter.setNumColumns(numColumns);
  }
}

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

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  int width = MeasureSpec.getSize(widthMeasureSpec);
  final float density = getResources().getDisplayMetrics().density;
  getResources().getDimensionPixelSize(R.dimen.bottomsheet_default_sheet_width);
  appGrid.setNumColumns((int) (width / (columnWidthDp * density)));
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

代码示例来源:origin: orhanobut/dialogplus

@Override @NonNull
public View getView(@NonNull LayoutInflater inflater, ViewGroup parent) {
 View view = inflater.inflate(R.layout.dialog_grid, parent, false);
 View outMostView = view.findViewById(R.id.dialogplus_outmost_container);
 outMostView.setBackgroundResource(backgroundResource);
 gridView = view.findViewById(R.id.dialogplus_list);
 gridView.setNumColumns(columnNumber);
 gridView.setOnItemClickListener(this);
 gridView.setOnKeyListener(new View.OnKeyListener() {
  @Override public boolean onKey(View v, int keyCode, KeyEvent event) {
   if (keyListener == null) {
    throw new NullPointerException("keyListener should not be null");
   }
   return keyListener.onKey(v, keyCode, event);
  }
 });
 headerContainer = view.findViewById(R.id.dialogplus_header_container);
 footerContainer = view.findViewById(R.id.dialogplus_footer_container);
 return view;
}

代码示例来源:origin: liaohuqiu/android-GridViewWithHeaderAndFooter

@Override
public void setNumColumns(int numColumns) {
  super.setNumColumns(numColumns);
  mNumColumns = numColumns;
  ListAdapter adapter = getAdapter();
  if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
    ((HeaderViewGridAdapter) adapter).setNumColumns(numColumns);
  }
}

代码示例来源:origin: TommyLemon/APIJSON

gvMomentView.setNumColumns(pictureNum <= 1 ? 1 : 3);
if (adapter == null) {
  adapter = new GridAdapter(context).setHasName(false);

代码示例来源:origin: TommyLemon/APIJSON

});
gvGridPickerView.setNumColumns(numColumns);
gvGridPickerView.setAdapter(adapter);
gvGridPickerView.smoothScrollToPosition(itemPosition);

代码示例来源:origin: TommyLemon/Android-ZBLibrary

});
gvGridPickerView.setNumColumns(numColumns);
gvGridPickerView.setAdapter(adapter);
gvGridPickerView.smoothScrollToPosition(itemPosition);

代码示例来源:origin: mayubao/KuaiChuan

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
  View rootView = inflater.inflate(R.layout.fragment_apk, container, false);
  // Inflate the layout for this fragment
  ButterKnife.bind(this, rootView);
  if(mType == FileInfo.TYPE_APK){ //应用
    gv.setNumColumns(4);
  }else if(mType == FileInfo.TYPE_JPG){ //图片
    gv.setNumColumns(3);
  }else if(mType == FileInfo.TYPE_MP3){ //音乐
    gv.setNumColumns(1);
  }else if(mType == FileInfo.TYPE_MP4){ //视频
    gv.setNumColumns(1);
  }
  //Android6.0 requires android.permission.READ_EXTERNAL_STORAGE
  init();//初始化界面
  return rootView;
}

代码示例来源:origin: UweTrottmann/SeriesGuide

@Override
public void setNumColumns(int numColumns) {
  super.setNumColumns(numColumns);
  mNumColumnsSet = true;
  this.mNumColumns = numColumns;
  if (numColumns != AUTO_FIT && mAdapter != null) {
    mAdapter.setNumColumns(numColumns);
  }
}

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

private void showAlertDialog() {
   // Prepare grid view
   GridView gridView = new GridView(this);
   List<Integer>  mList = new ArrayList<Integer>();
   for (int i = 1; i < 36; i++) {
     mList.add(i);
   }
   gridView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, mList));
   gridView.setNumColumns(5);
   gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
     @Override
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       // do something here
     }
   });
   // Set grid view to alertDialog
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setView(gridView);
   builder.setTitle("Goto");
   builder.show();
 }

代码示例来源: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: stackoverflow.com

mGrid.setNumColumns(Math.min(plainTextActivities.size(), mMaxColumns));

代码示例来源:origin: 1993hzw/Doodle

/**
 * 列数
 *
 * @param count
 */
public void setColumnCount(int count) {
  mGridView.setNumColumns(count);
}

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

GridView gridView = (GridView)inflater.inflate(R.layout.mygrid, null);
gridView.setLayoutParams(new GridView.LayoutParams(customValue, 
            LayoutParams.FILL_PARENT));
gridView.setNumColumns(someInt);
gridView.setAdapter (new MyCustomAdapter(this));

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

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GridView gridView = new GridView(this);
gridView.setNumColumns(3);
setContentView(gridView);
gridView.setAdapter(new GridViewAdapter(this));
}

代码示例来源:origin: zzkong/BaseProject

@Override
public void setNumColumns(int numColumns) {
  super.setNumColumns(numColumns);
  mNumColumns = numColumns;
  ListAdapter adapter = getAdapter();
  if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
    ((HeaderViewGridAdapter) adapter).setNumColumns(numColumns);
  }
}

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

GridView grid = new GridView( this );
grid.setColumnWidth( UIScheme.cellSize );
grid.setVerticalSpacing( UIScheme.gap );
grid.setStretchMode( GridView.STRETCH_COLUMN_WIDTH );
grid.setNumColumns( GridView.AUTO_FIT );

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

GridView grid = new GridView(this);
 grid.setId(ViewIdentification.getId());
 grid.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
 grid.setBackgroundColor(Color.WHITE);
 grid.setNumColumns(3);
 grid.setColumnWidth(GridView.AUTO_FIT);
 grid.setVerticalSpacing(5);
 grid.setHorizontalSpacing(5);
 grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);

相关文章

GridView类方法