Adjust popup window size

0

How to adjust the size of the popup window to layout content?

I tried, unsuccessfully, the following:

LayoutInflater inflater = (LayoutInflater) m_activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.main_info_window, null, false);

view.requestLayout();

PopupWindow pw = new PopupWindow(view,view.getWidth(),view.getHeight(),true);

main_info_window.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="20dp"
              android:background="#CCCCCCCC">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Info window"
        android:layout_gravity="center"/>

</LinearLayout>
    
asked by anonymous 11.11.2016 / 21:03

1 answer

1

In the creation of the PopupWindow object change to:

PopupWindow pw = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,true);

** you do not need to call the method view.requestLayout ();

    
11.11.2016 / 23:59