本文整理了Java中android.widget.GridView.getLayoutParams()
方法的一些代码示例,展示了GridView.getLayoutParams()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridView.getLayoutParams()
方法的具体详情如下:
包路径:android.widget.GridView
类名称:GridView
方法名:getLayoutParams
暂无
代码示例来源:origin: stackoverflow.com
label.getLayoutParams().height = GRID_HEIGHT;
代码示例来源:origin: stackoverflow.com
private void resizeGridView(GridView gridView, int items, int columns) {
ViewGroup.LayoutParams params = gridView.getLayoutParams();
int oneRowHeight = gridView.getHeight();
int rows = (int) (items / columns);
params.height = oneRowHeight * rows;
gridView.setLayoutParams(params);
}
代码示例来源:origin: stackoverflow.com
private void resizeGridView(GridView gridView, int items, int columns) {
ViewGroup.LayoutParams params = gridView.getLayoutParams();
int oneRowHeight = gridView.getHeight();
int rows = (int) (items / columns);
params.height = oneRowHeight * rows;
gridView.setLayoutParams(params);
}
代码示例来源:origin: LRH1993/LiveCircle
private void setHeaderItemValues(HeaderViewHolder holder) {
NewsChannelGridAdapter mAdapter = new NewsChannelGridAdapter(mTables, context);
holder.mGridView.setAdapter(mAdapter);
//解决GridView只显示一行的原因 主动设置GridView的高度
ViewGroup.LayoutParams params = holder.mGridView.getLayoutParams();
View view = mAdapter.getView(0, null, holder.mGridView);
view.measure(0,0);
int height =view.getMeasuredHeight();
int totalHeight = holder.mGridView.getVerticalSpacing() * 2 + height * 2;
params.height = totalHeight;
holder.mGridView.setLayoutParams(params);
}
代码示例来源:origin: mouxuefei/KotlinMvpExample
/**
* 动态设置gridView的高度
*
* @param gridView
* @param columns 列数
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public static void setGridViewHeight(GridView gridView, int columns) {
ListAdapter adapter = gridView.getAdapter();
int count = adapter.getCount();
int row = count / columns;
row = (count % columns) == 0 ? row : (row + 1);
int totalHeight = 0;
for (int i = 0; i < row; i++) {
View view = adapter.getView(i, null, gridView);
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams layoutParams = gridView.getLayoutParams();
layoutParams.height = totalHeight + (gridView.getVerticalSpacing() * (row - 1));
gridView.setLayoutParams(layoutParams);
}
代码示例来源: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: HenriDellal/emerald
mainLayout.addView(getFakeStatusBar(mainLayout, layoutInflater, options));
layoutParams = new RelativeLayout.LayoutParams(grid.getLayoutParams());
if (kitkatNoImmersiveMode) {
layoutParams.addRule(RelativeLayout.BELOW, R.id.kitkat_status_bar);
mainLayout.addView(mainBar);
layoutParams = new RelativeLayout.LayoutParams(grid.getLayoutParams());
layoutParams.addRule(RelativeLayout.ABOVE, R.id.dock_bar);
layoutParams.addRule(RelativeLayout.BELOW, R.id.main_bar);
代码示例来源:origin: zhe525069676/WeiBoLayout
ViewGroup.LayoutParams params = gridView.getLayoutParams();
代码示例来源:origin: stackoverflow.com
private static void resizeGridView(GridView gridView, int rows) {
int measuredHeight = gridView.getMeasuredHeight();
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = measuredHeight * rows;
gridView.setLayoutParams(params);
gridView.requestLayout();
}
代码示例来源: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: sealtalk/sealtalk-android
public void setGridViewHeight(GridView gridView) {
if (gridView == null) {
return;
}
ViewGroup.LayoutParams params = gridView.getLayoutParams();
//获取ActionBar高度
TypedValue tv = new TypedValue();
int actionBarHeight = 0;
if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, mContext.getResources().getDisplayMetrics());
}
/**
* 获取状态栏高度
* */
int statusBarHeight = 0;
if (getResources() != null) {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
//根据资源ID获取响应的尺寸值
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
}
params.height = getScreenHeight() - getSolidHeight() - actionBarHeight - statusBarHeight;
// 设置参数
gridView.setLayoutParams(params);
}
代码示例来源: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
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = totalHeight;
gridView.setLayoutParams(params);
代码示例来源:origin: dengshiwei/AndroidUtils
ViewGroup.LayoutParams params = gv.getLayoutParams();
params.height = totalHeight + gv.getPaddingTop() + gv.getPaddingBottom() + 2;
LogUtil.d("MeasureUtil", "gridview-height--" + params.height);
代码示例来源:origin: chengzichen/KrGallery
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView
.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
内容来源于网络,如有侵权,请联系作者删除!