title: How to change position of showAsDropdown popup window if there is not enough space in the bottom?
body: <p>I am using a <code>recyclerview</code> which has a menu for each of its item. I am using a pop up window to achieve the same instead of pop up <code>menu</code> as I have a customized layout. The issue that I am facing is that when I open the menu from the items at bottom of the screen my menu is not fully visible and gets cut is there a way to solve it? </p>
  
  <p><a href="https://i.stack.imgur.com/BJ9Nm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BJ9Nm.png" alt="Here is the screenshot"></a></p>
  
  <p>Here is my Menu( it has 4 options)</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/menuItemLayout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/shadow_menu"
      android:gravity="center"
      android:orientation="vertical"&gt;
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@color/white"
          android:orientation="vertical"&gt;
  
      &lt;LinearLayout
          android:id="@+id/menuAttendeeMeet"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="?android:attr/selectableItemBackground"
          android:clickable="true"
          android:gravity="center_vertical"
          android:orientation="horizontal"
          android:layout_marginTop="9dp"
          android:paddingBottom="12dp"
          android:paddingTop="12dp"&gt;
  
          &lt;ImageView
              android:id="@+id/ivattendee_meet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"
              android:src="@drawable/meet_icon" /&gt;
  
          &lt;TextView
              android:id="@+id/tvattendee_meet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Meet"
              android:layout_marginRight="16dp"
              android:textColor="@color/textPrimary"
              android:textSize="16dp" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/menuAttendeeChat"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="?android:attr/selectableItemBackground"
          android:clickable="true"
          android:gravity="center_vertical"
          android:orientation="horizontal"
          android:paddingBottom="12dp"
          android:paddingTop="12dp"&gt;
  
          &lt;ImageView
              android:id="@+id/ivattendee_chat"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"
              android:src="@drawable/chat_icon" /&gt;
  
          &lt;TextView
              android:id="@+id/tvattendee_chat"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Chat"
              android:layout_marginRight="16dp"
              android:textColor="@color/textPrimary"
              android:textSize="16dp" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/menuAttendeeTakeANote"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="?android:attr/selectableItemBackground"
          android:clickable="true"
          android:gravity="center_vertical"
          android:orientation="horizontal"
          android:paddingBottom="12dp"
          android:paddingTop="12dp"&gt;
  
          &lt;ImageView
              android:id="@+id/ivattendee_note"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"
              android:src="@drawable/take_a_note_icon" /&gt;
  
          &lt;TextView
              android:id="@+id/tvattendee_note"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Take a note"
              android:layout_marginRight="16dp"
              android:textColor="@color/textPrimary"
              android:textSize="16dp" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/menuAttendeeBusinessCard"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="?android:attr/selectableItemBackground"
          android:clickable="true"
          android:gravity="center_vertical"
          android:layout_marginBottom="9dp"
          android:orientation="horizontal"
          android:paddingBottom="12dp"
          android:paddingTop="12dp"&gt;
  
          &lt;ImageView
              android:id="@+id/ivattendee_business_card"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"
              android:src="@drawable/business_card_icon" /&gt;
  
          &lt;TextView
              android:id="@+id/tvattendee_business_card"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Business Card"
              android:layout_marginRight="16dp"
              android:textColor="@color/textPrimary"
              android:textSize="16dp" /&gt;
      &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is my pop up window inside the adapter:</p>
  
  <pre><code>final PopupWindow popupWindow = new PopupWindow(v.getContext());
  LayoutInflater inflater = (LayoutInflater) v.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
  View view = inflater.inflate(R.layout.layout_pop_up_menu_attendee, null);
  popupWindow.setFocusable(true);
  popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  popupWindow.setOutsideTouchable(true);
  popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
  popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
  popupWindow.setContentView(view);
  
  int ivHeight = holder.ivAttendeeMenu.getHeight() - 20;
  if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
      popupWindow.showAsDropDown(holder.ivAttendeeMenu, 0, -ivHeight, Gravity.END);
  }
  View container;
  if (android.os.Build.VERSION.SDK_INT &gt; 22) {
      container = (View) popupWindow.getContentView().getParent().getParent();
  } else {
      container = (View) popupWindow.getContentView().getParent();
  }
  
  WindowManager wm = (WindowManager) v.getContext().getSystemService(Context.WINDOW_SERVICE);
  WindowManager.LayoutParams p = (WindowManager.LayoutParams) container.getLayoutParams();
  
  p.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
  p.dimAmount = 0.3f;
  wm.updateViewLayout(container, p);
  </code></pre>