本文整理了Java中android.widget.GridView.getWidth()
方法的一些代码示例,展示了GridView.getWidth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridView.getWidth()
方法的具体详情如下:
包路径:android.widget.GridView
类名称:GridView
方法名:getWidth
暂无
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
if (mAdapter.getNumColumns() == 0) {
final int numColumns = (int) Math.floor(
mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
if (numColumns > 0) {
final int columnWidth =
(mGridView.getWidth() / numColumns) - mImageThumbSpacing;
mAdapter.setNumColumns(numColumns);
mAdapter.setItemHeight(columnWidth);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mGridView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
} else {
mGridView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
}
}
}
});
代码示例来源:origin: jeasonlzy/ImagePicker
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
int size = gridView.getWidth() / 3;
if (convertView == null) {
imageView = new ImageView(ImagePickerActivity.this);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, size);
imageView.setLayoutParams(params);
imageView.setBackgroundColor(Color.parseColor("#88888888"));
} else {
imageView = (ImageView) convertView;
}
imagePicker.getImageLoader().displayImage(ImagePickerActivity.this, getItem(position).path, imageView, size, size);
return imageView;
}
}
代码示例来源:origin: caohaoping/PhotosWall
@Override
public void onGlobalLayout() {
// 计算列数
final int numColumns = (int) Math.floor(mPhotoWallView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
if (numColumns > 0) {
int columnWidth = (mPhotoWallView.getWidth() / numColumns) - mImageThumbSpacing;
mWallAdapter.setItemSize(columnWidth);
mPhotoWallView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
代码示例来源:origin: googlecodelabs/android-topeka
/**
* Calculates spans for avatars dynamically.
*
* @return The recommended amount of columns.
*/
private int calculateSpanCount() {
int avatarSize = getResources().getDimensionPixelSize(R.dimen.size_fab);
int avatarPadding = getResources().getDimensionPixelSize(R.dimen.spacing_double);
return mAvatarGrid.getWidth() / (avatarSize + avatarPadding);
}
}
代码示例来源:origin: WuXiaolong/WoChat
@TargetApi(VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
final int numColumns = (int) Math.floor(mGridView
.getWidth()
/ (mImageThumbSize + mImageThumbSpacing));
if (numColumns > 0) {
final int columnWidth = (mGridView.getWidth() / numColumns)
- mImageThumbSpacing;
mAdapter.setItemHeight(columnWidth);
if (BuildConfig.DEBUG) {
Log.d(TAG,
"onCreateView - numColumns set to "
+ numColumns);
}
if (Utils.hasJellyBean()) {
mGridView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
} else {
mGridView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
}
}
});
代码示例来源:origin: easemob/kefu-android-demo
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
final int numColumns = (int) Math.floor(mGridView
.getWidth()
/ (mImageThumbSize + mImageThumbSpacing));
if (numColumns > 0) {
final int columnWidth = (mGridView.getWidth() / numColumns)
- mImageThumbSpacing;
mAdapter.setItemHeight(columnWidth);
// if (BuildConfig.DEBUG) {
// Log.d(TAG,
// "onCreateView - numColumns set to "
// + numColumns);
// }
if (Utils.hasJellyBean()) {
mGridView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
} else {
mGridView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
}
}
});
代码示例来源:origin: huangfangyi/FanXin
@TargetApi(VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
final int numColumns = (int) Math.floor(mGridView
.getWidth()
/ (mImageThumbSize + mImageThumbSpacing));
if (numColumns > 0) {
final int columnWidth = (mGridView.getWidth() / numColumns)
- mImageThumbSpacing;
mAdapter.setItemHeight(columnWidth);
if (BuildConfig.DEBUG) {
Log.d(TAG,
"onCreateView - numColumns set to "
+ numColumns);
}
if (Utils.hasJellyBean()) {
mGridView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
} else {
mGridView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
}
}
});
代码示例来源:origin: stackoverflow.com
public static void setDynamicHeightGridView(GridView mListView,String oddeven) {
ListAdapter mListAdapter = mListView.getAdapter();
if (mListAdapter == null) {
return;
}
int height = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(mListView.getWidth(), View.MeasureSpec.UNSPECIFIED);
for(int i = 0; i < mListAdapter.getCount(); i++){
View listItem = mListAdapter.getView(i, null, mListView);
listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
height += listItem.getMeasuredHeight();
itemHeight=listItem.getMeasuredHeight()/3;
}
ViewGroup.LayoutParams params = mListView.getLayoutParams();
if(oddeven.equals("odd")){
if(mListAdapter.getCount()>=5){
int count=((mListAdapter.getCount()-5)/2) + 1;
params.height = ((height - (height / 3)) - (itemHeight * count)) + 20 + (count * 5);
}else{
params.height = height - (height / 3) + 20;
}
}else if(oddeven.equals("even")) {
params.height = height/2 + 20;
}
mListView.setLayoutParams(params);
mListView.requestLayout();
}
代码示例来源:origin: stackoverflow.com
gwight = gridview1.getWidth();
ghight = gridview1.getHeight();
try {
代码示例来源:origin: zxfnicholas/CameraSDK
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void onGlobalLayout() {
final int width = mGridView.getWidth();
final int height = mGridView.getHeight();
// mGridWidth = width;
// mGridHeight = height;
final int desireSize = getResources().getDimensionPixelOffset(R.dimen.image_size);
final int numCount = width / desireSize;
final int columnSpace = getResources().getDimensionPixelOffset(R.dimen.space_size);
int columnWidth = (width - columnSpace*(numCount-1)) / numCount;
mImageAdapter.setItemSize(columnWidth);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}else{
mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
代码示例来源:origin: stackoverflow.com
public static void setHeightDynamically(GridView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i = i+2) {
view = listAdapter.getView(i, view, listView);
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight;
listView.setLayoutParams(params);
listView.requestLayout();
}
代码示例来源:origin: stackoverflow.com
@Override public View getView(final int pos, View convertView, ViewGroup parent) {
g[pos].setLayoutParams(new GridView.LayoutParams(gv.getWidth(), gv.getHeight()));
return g[pos];
ImageView mIV = new ImageView(Test.this);
mIV.setBackgroundResource(images[pos]);
mIV.setLayoutParams(new Gallery.LayoutParams(gv.getWidth(), gv.getHeight()/3));
return mIV;
代码示例来源:origin: stackoverflow.com
public static void setGridViewHeightBasedOnChildren(GridView gridView, int columns) {
ListAdapter listAdapter = gridView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(gridView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
int rows = listAdapter.getCount() / columns;
if(listAdapter.getCount() % columns> 0){
rows++;
}
for (int i = 0; i < rows; i++) {
view = listAdapter.getView(i, view, gridView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LinearLayout.LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = totalHeight + (gridView.getHorizontalSpacing() * rows);
gridView.setLayoutParams(params);
gridView.requestLayout();
}
代码示例来源:origin: stackoverflow.com
public View getView(final int pos, View convertView, ViewGroup parent) {
g[pos].setLayoutParams(new GridView.LayoutParams(gv.getWidth(), gv
.getHeight()));
return g[pos];
ImageView mIV = new ImageView(Test.this);
mIV.setBackgroundResource(images[pos]);
mIV.setLayoutParams(new Gallery.LayoutParams(gv.getWidth(), gv
.getHeight() / 3));
return mIV;
代码示例来源:origin: stackoverflow.com
mCellWidth = mGrid.getWidth()/numberOfColumns;
mCellHeight = mGrid.getHeight()/numberOfRows;
mGrid.setColumnWidth(mCellWidth);
内容来源于网络,如有侵权,请联系作者删除!