我需要帮助来重新调整当前菜单项的大小。我创建了一个自定义菜单,其中包含以编程方式添加的项目TableLayout
。这是我目前的菜单:
我需要更改第一个菜单的高度。现在的问题是,当我改变第一个菜单项的高度时,整个菜单都会改变它的高度。我想要这样的菜单:
有没有办法重新调整我当前项目的大小?
public synchronized void show(View v) {
mIsShowing = true;
boolean isLandscape = false;
int itemCount = mMenuItems.size();
if (itemCount<1) return; //no menu items to show
if (mPopupWindow != null) return; //already showing
Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
if (display.getWidth() > display.getHeight()) isLandscape = true;
View mView= mLayoutInflater.inflate(R.layout.custom_menu, null);
mPopupWindow = new PopupWindow(mView,LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT, false);
mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
mPopupWindow.setWidth(display.getWidth());
mPopupWindow.showAtLocation(v, Gravity.BOTTOM, 0, 0);
int divisor = mItemsPerLineInPortraitOrientation;
if (isLandscape) divisor = mItemsPerLineInLandscapeOrientation;
int remainder = 0;
if (itemCount < divisor) {
mRows = 1;
remainder = itemCount;
} else {
mRows = (itemCount / divisor);
remainder = itemCount % divisor;
if (remainder != 0) mRows++;
}
TableLayout table = (TableLayout)mView.findViewById(R.id.custom_menu_table);
table.removeAllViews();
for (int i=0; i < mRows; i++) {
TableRow row = null;
TextView tv = null;
ImageView iv = null;
row = new TableRow(mContext);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
for (int j=0; j< divisor; j++) {
if (i*divisor+j >= itemCount) break;
final CustomMenuItem cmi = mMenuItems.get(i*divisor+j);
View itemLayout = mLayoutInflater.inflate(R.layout.custom_menu_item, null);
if (j==0)
{
itemLayout.setBackgroundResource(R.drawable.current_menu);
itemLayout.setPadding(5, 5, 5, 5);
}
tv = (TextView)itemLayout.findViewById(R.id.custom_menu_item_caption);
tv.setText(cmi.getCaption());
iv = (ImageView)itemLayout.findViewById(R.id.custom_menu_item_icon);
iv.setImageResource(cmi.getImageResourceId());
itemLayout.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
mListener.MenuItemSelectedEvent(cmi);
if (mHideOnSelect) hide();
}
});
row.addView(itemLayout);
}
table.addView(row);
}
}
如果我为整行提供背景而不是结果 如果通过此行为布局(每个菜单项)提供背景 itemLayout.setBackgroundResource(R.drawable.menubackground);
但我想看起来像这个菜单