I inflate a ListView inside a PopupWindow and I want the popup to behave like this:
I have found the solution by myself. For anyone who will ever stumble upon this problem, the answer is to override the method onMeasure()
of the ListView like this:
public class MyListView extends ListView {
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//set your custom height. AT_MOST means it can be as tall as needed,
//up to the specified size.
int height = MeasureSpec.makeMeasureSpec(300,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec,height);
}
}