本文整理匯總了Java中android.widget.GridLayout.getColumnCount方法的典型用法代碼示例。如果您正苦於以下問題:Java GridLayout.getColumnCount方法的具體用法?Java GridLayout.getColumnCount怎麽用?Java GridLayout.getColumnCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.GridLayout
的用法示例。
在下文中一共展示了GridLayout.getColumnCount方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.widget.GridLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_property_animation);
mBtnXXml = (ImageButton) findViewById(R.id.btn_x_xml);
mBtnXCode = (ImageButton) findViewById(R.id.btn_x_code);
mGridLayout = (GridLayout) findViewById(R.id.grid);
findViewById(R.id.btn_grid).setOnClickListener(this);
mBtnXXml.setOnClickListener(this);
mBtnXCode.setOnClickListener(this);
// GridLayoutにボタンを複數追加
int maxChild = mGridLayout.getRowCount() * mGridLayout.getColumnCount();
for (int i = 0; i < maxChild; i++) {
Button button = (Button) getLayoutInflater().inflate(R.layout.activity_main_button, mGridLayout, false);
button.setText(i + "");
mGridLayout.addView(button);
}
}
示例2: onWindowFocusChanged
import android.widget.GridLayout; //導入方法依賴的package包/類
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
// GridLayout內のアイテムをレイアウトサイズに合わせてストレッチ
final GridLayout gl = (GridLayout) findViewById(R.id.calcFrame);
int childWidth = gl.getWidth() / gl.getColumnCount();
int childHeight = gl.getHeight() / gl.getRowCount();
for (int i = 0; i < gl.getChildCount(); i++) {
gl.getChildAt(i).setMinimumWidth(childWidth);
gl.getChildAt(i).setMinimumHeight(childHeight);
}
}
示例3: getAppLauncherLayoutParams
import android.widget.GridLayout; //導入方法依賴的package包/類
@NonNull
private GridLayout.LayoutParams getAppLauncherLayoutParams(GridLayout grid, AppLauncher app) {
GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
int w = getLauncherWidth(app);
int h = getLauncherHeight(app);
if (w>0 || h>0) {
//float sw = getResources().getDimension(R.dimen.launcher_width);
float sw = mStyle.getLauncherSize();
//float sh = getResources().getDimension(R.dimen.launcher_height);
//int width = (int)(sw + 20) * mColumns;
float cellwidth = sw * 1f;
float cellheight = cellwidth + 5; // ~square cells
int wcells = (int) Math.ceil(w / cellwidth);
if (wcells > 1) {
int start = GridLayout.UNDEFINED;
if (wcells > grid.getColumnCount()) {
wcells = grid.getColumnCount();
}
// if (wcells > 1) start = 0;
lp.columnSpec = GridLayout.spec(start, wcells, GridLayout.FILL);
//Log.d("widcol", "w=" + w + " wcells=" + wcells + " start=" + start + " cellwidth=" + cellwidth + " r=" + cellwidth * wcells);
} else {
lp.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1, GridLayout.FILL);
}
int hcells = (int) Math.ceil(h / cellheight);
if (hcells > 1) {
lp.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, hcells, GridLayout.FILL);
} else {
lp.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, 1, GridLayout.FILL);
}
final AppWidgetHostView appwid = mLoadedWidgets.get(app.getActivityName());
if (appwid != null) {
//appwid.updateAppWidgetSize(null, (int) sw, (int) sh, (int) (cellwidth * wcells), (int) (cellheight * hcells));
//magic numbers to properly expand widgets...
final int wDp = pxToDip(cellwidth*wcells);
final int hDp = pxToDip(cellheight*hcells*4/3);
lp.width = (int)(cellwidth*wcells*1.1);
lp.height = (int)(cellheight*hcells*4/3);
//Log.d("widcol2", "w=" + w + " wcells=" + wcells + " cellwidth=" + cellwidth + " r=" + cellwidth * wcells);
//Log.d("widcol2", "h=" + w + " hcells=" + hcells + " cellheight=" + cellheight + " r=" + cellheight * hcells);
appwid.postDelayed(new Runnable() {
@Override
public void run() {
appwid.updateAppWidgetSize(null, wDp, hDp, wDp, hDp);
if (appwid.getParent()!=null) {
appwid.getParent().requestLayout();
}
appwid.requestLayout();
}
}, 1000);
}
}
return lp;
}