improve size calculation
This commit is contained in:
parent
89b110e5ea
commit
f8fd73999e
@ -193,10 +193,17 @@ public class FancyMenu {
|
|||||||
* @param the estimated height
|
* @param the estimated height
|
||||||
* @return the height to use instead of the input
|
* @return the height to use instead of the input
|
||||||
*/
|
*/
|
||||||
private int getMenuHeight(int suggested) {
|
private int getMenuHeight(View parent, int suggested) {
|
||||||
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
||||||
int maxHeight = (int)((float)metrics.heightPixels * 0.35);
|
int pos[] = new int[2];
|
||||||
return (suggested > maxHeight ? maxHeight : ListPopupWindow.WRAP_CONTENT);
|
// Don't calculate a size which is less than 20% of the screen space
|
||||||
|
// (unless the menu is smaller than that)
|
||||||
|
int min = metrics.heightPixels / 5;
|
||||||
|
|
||||||
|
parent.getLocationInWindow(pos);
|
||||||
|
int available = metrics.heightPixels - pos[1] - parent.getHeight();
|
||||||
|
available = Math.max(available, min);
|
||||||
|
return Math.min(available, suggested);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,7 +229,7 @@ public class FancyMenu {
|
|||||||
|
|
||||||
int result[] = new int[2];
|
int result[] = new int[2];
|
||||||
measureAdapter(adapter, result);
|
measureAdapter(adapter, result);
|
||||||
pw.setHeight(getMenuHeight(result[0]));
|
pw.setHeight(getMenuHeight(parent, result[0]));
|
||||||
pw.setWidth(result[1]);
|
pw.setWidth(result[1]);
|
||||||
|
|
||||||
pw.setAdapter(adapter);
|
pw.setAdapter(adapter);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user