How to set the height of popup window in android Java

527 Views Asked by At

[![enter image description here][1]][1]

Hi, How can achieve the above image. when user clicks on the profile icon then the pop up window will display. But here the problem i am getting is pop up window is covering the whole height from anchor view. I need to show that home and barcode images bottom navigation view.

My XML Code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:background="@drawable/menu">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Menu"
            android:textSize="30sp"
            android:layout_marginBottom="60dp"
            android:layout_gravity="center"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:gravity="center"
            android:fontFamily="@font/robotobold"
            android:layout_marginTop="20dp"
            android:textColor="@color/colorBlack">
        </TextView>

        <TextView
            android:id="@+id/agent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Agent Agreement"
            android:layout_margin="10dp"
            android:textSize="14sp"
            android:layout_gravity="start"
            android:gravity="start"
            android:fontFamily="@font/robotobold"
            android:textColor="@color/colorBlack">
        </TextView>
        <TextView
            android:id="@+id/privacypolicy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Privacy Policy"
            android:layout_margin="10dp"
            android:textSize="14sp"
            android:layout_gravity="start"
            android:gravity="start"
            android:fontFamily="@font/robotobold"
            android:textColor="@color/colorBlack">
        </TextView>
        <TextView
            android:id="@+id/changesettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="How to change your settings"
            android:layout_margin="10dp"
            android:textSize="14sp"
            android:layout_gravity="start"
            android:gravity="start"
            android:fontFamily="@font/robotobold"
            android:textColor="@color/colorBlack">
        </TextView>
        <TextView
            android:id="@+id/bankinfo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your Bank Account Info"
            android:layout_margin="10dp"
            android:textSize="14sp"
            android:layout_gravity="start"
            android:gravity="start"
            android:fontFamily="@font/robotobold"
            android:textColor="@color/colorBlack">
        </TextView>
        <TextView

            android:id="@+id/profilepic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Profile Picture"
            android:layout_margin="10dp"
            android:textSize="14sp"
            android:layout_gravity="start"
            android:gravity="start"
            android:fontFamily="@font/robotobold"
            android:textColor="@color/colorBlack">
        </TextView>
        <TextView
            android:id="@+id/logout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Logout"
            android:layout_margin="10dp"
            android:textSize="14sp"
            android:layout_gravity="start"
            android:gravity="start"
            android:fontFamily="@font/robotobold"
            android:textColor="@color/colorBlack">
        </TextView>

    </LinearLayout>

</RelativeLayout>

and Java code for displaying pop window

 draweeView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showPopup(view) ;
}
});
 

     private void showPopup(View view) {
            View popupView = getLayoutInflater().inflate(R.layout.menupopup, null);
             popupWindow.setFocusable(true);
           PopupWindow popupWindow = new PopupWindow(popupView,
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    
         
            TextView tv = (TextView) popupView.findViewById(R.id.lesshigh);
    
    
          
            popupWindow.showAsDropDown(view,-25, 10);
    
        }

The result I am getting is:enter image description here

1

There are 1 best solutions below

1
On

Change the values of android:layout_height in your LinearLayout. For me the best what can you do will be look like this :

...
<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
...