Home » Android » Text clipping inside ListPopupWindow on Android

Text clipping inside ListPopupWindow on Android

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a ListPopupWindow defined as below in my Android application.

    ListPopupWindow listPopupWindow;

    listPopupWindow = new ListPopupWindow(RootView.this);
    listPopupWindow.setAdapter(new ArrayAdapter<String>(RootView.this,
            R.layout.push_list_item, pushMessages));
    listPopupWindow.setAnchorView(bEvents);
    listPopupWindow.setWidth(300);
    listPopupWindow.setHeight(400);
    listPopupWindow.setModal(true);
    listPopupWindow.show();

The XML for the layout referenced above is given below..

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FF0000"
    android:paddingLeft="6dp"
    android:textSize="12sp"
    android:maxLines="3"
    android:lines="3"
    android:ellipsize="end"
    android:textStyle="bold" />

When I get a text that is larger in size, the text just seems to clip as opposed to wrap, even though I have specified the correct attributes inside the XML. Can anyone help me understand what is going on here, and propose a solution for my problem.

Thanks..

How to&Answers:

The main problem you should get with your xml file that it’s not possible to have >2 lines + ellipsize.

You should implement you own EllipsizeTextView to support real multiline ellipsized textview.

You could find an example here and here.

Also you could find this bug here.