Adjust the size of the popup window

Asked

Viewed 58 times

0

How to adjust the popup window size to the 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>

1 answer

1

When creating the Popupwindow object change to:

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

** no need to call the method view.requestLayout();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.