0

I'm trying to add a custom ListPopupWindow to a TextView wrapped in a TextInputLayout. The TextView has an OnClick listener that creates and shows the ListPopupWindow. Effectively I'm working on a custom Spinner.

If I change the TextInputLayout to a LinearLayout the ListPopupWindow displays correctly. Otherwise, the visual error is extra padding at the bottom of the popup.

XML:

<android.support.design.widget.TextInputLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">

   <com.project.CustomTextView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"/>

</android.support.design.widget.TextInputLayout>

CustomTextView:

@Override
public void onClick(View v) {
    ArrayList<String> list = new ArrayList<>();
    list.add("Item 1");
    list.add("Item 2");

    ListPopupWindow popup = new ListPopupWindow(getContext());

    popup.setAnchorView(this);
    popup.setHeight(ListPopupWindow.WRAP_CONTENT);

    popup.setAdapter(new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, list));
    popup.show();
}

Result:

(This is just my non-generic implementation I'm working on. Notice the clipped bottom of the list. There is a ~30dp padding there that can't be removed). Notice the clipped bottom

soundsofpolaris
  • 596
  • 3
  • 12

1 Answers1

0

For anyone trying to solve this issue: It is definitely an issue with TextInputLayout being the anchor view for the popup. Here is how I got around it for now. Basically, add a LinearLayout to the TextInputLayout and use its parent for the context.

    LinearLayout menuAnchor = new LinearLayout(((ViewGroup) getParent()).getContext());
    addView(menuAnchor, 0);

    popup = new ListPopupWindow(menuAnchor.getContext());
    popup.setAnchorView(menuAnchor);
soundsofpolaris
  • 596
  • 3
  • 12