0
我將gridview放入對話框中,但無法以任何方式更改其大小,它始終以水平方向填充屏幕。如何更改對話框中的網格視圖寬度
protected Dialog getMoreMenuDialog(GridView gridView) {
Dialog d = new Dialog(AbstractActivity.this, R.style.menuDialog);
Window window = d.getWindow();
window.setGravity(Gravity.BOTTOM);
android.view.WindowManager.LayoutParams params = window.getAttributes();
params.y = findViewById(R.id.context_menu_ll).getHeight() + 3;
window.setAttributes(params);
d.setCancelable(true);
d.setCanceledOnTouchOutside(true);
int WRAP_CONTENT = LayoutParams.WRAP_CONTENT;
gridView.setLayoutParams(new LayoutParams(100, WRAP_CONTENT));
d.addContentView(gridView, new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
return d;
}
下一個是地方調用此方法
LayoutInflater factory = LayoutInflater.from(this);
final GridView gridView = (GridView) factory.inflate(R.layout.winner_moremenu, null);
mMoreMenuItemsGridView = gridView;
// gridView.setAdapter(new
// MenuAdapter(getApplicationContext(),getMoreMenuItems()));
OnItemClickListener il = getMenuGridOnItemClickListener();
if (il == null) {
il = mDefaultMoreMenuListener;
}
gridView.setOnItemClickListener(il);
return getMoreMenuDialog(gridView);
是什麼R.layout.winner_moremenu?接下來
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:numColumns="4"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:listSelector="@drawable/shap_context_menu_focus"
android:gravity="center"
/>