我需要幫助來重新調整我的當前菜單項的大小。我創建了一個自定義菜單,其中編程添加了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);
但我想是這樣的菜單
你能發佈你的代碼嗎? – Martin 2013-02-14 07:36:56