Search code examples
androiddialogpopupandroid-5.0-lollipop

Can't set height and width of Popup Window


I made a layout for popup window and when i click on button to display popup window it doesn't show popup dialog correctly and only partial view is seen like this

enter image description here

when i click on 3 dots.

I want my popup to display like this

enter image description here

when i click on 3 dots.

Here is my code.

 LayoutInflater layoutInflater
                            = (LayoutInflater)getBaseContext()
                            .getSystemService(LAYOUT_INFLATER_SERVICE);
                    final View popupView = layoutInflater.inflate(R.layout.custom_dialog, null);
                    final PopupWindow popupWindow = new PopupWindow(
                            popupView,
                            WindowManager.LayoutParams.WRAP_CONTENT,
                            WindowManager.LayoutParams.WRAP_CONTENT);
                    ImageButton gmail= (ImageButton) popupView.findViewById(R.id.gmail);
                    gmail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v)
                        {
                            popupWindow.dismiss();
                        }
                    });

                    popupWindow.showAsDropDown(view.findViewById(R.id.more));

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">


<ImageButton
    android:id="@+id/gmail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/gmail"
    android:backgroundTint="#000000"
    android:layout_weight="0.25"/>

<ImageButton
    android:id="@+id/hike"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/hike"
    android:backgroundTint="#000000"
    android:scaleType="fitXY"
    android:layout_weight="0.25"/>

<ImageButton
    android:id="@+id/hangouts"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="#000000"
    app:srcCompat="@drawable/hangouts"
    android:scaleType="fitXY"
    android:layout_weight=".25"/>

<ImageButton
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/message"
    android:scaleType="fitXY"
    android:backgroundTint="#000000"
    android:layout_weight=".25"/>
 </LinearLayout>

can anybody tell me where i made the mistake? Thanks in advance. THANK YOU ALL THE PEOPLE FOR YOUR HELP


Solution

  • replace app:srcCompat="@drawable/hike" with android:src="@drawable/hike"