title: Trouble working with showAtLocation(View, int, int, int) for PopupWindow
body: <p>I am trying to create a popup that when launch would be at the center of this screen, and where its width would not take the entire screen, regardless where the button to prompt it was situated at. I also wanted to add transparency so that users are vaguely able to see the activity now in background, but I also experienced issues working with alpha. My attempt so far have been unsatisfactory.</p>
  
  <p>In particular, when attempting to use gravity in the showAtLocation method, i get prompted with the following error message:
  "The method showAtLocation(View, int, int, int) in the type PopupWindow is not applicable for the argument"</p>
  
  <p>Any assistance would be greatly appreciated; thanks in advance.</p>
  
  <p>Below is the activity code</p>
  
  <pre><code>import android.app.Activity; 
  import android.graphics.Color;
  import android.os.Bundle; 
  import android.view.Gravity;
  import android.view.View; 
  import android.view.View.OnClickListener; 
  import android.view.ViewGroup.LayoutParams; 
  import android.widget.Button; 
  import android.widget.LinearLayout; 
  import android.widget.PopupWindow; 
  import android.widget.TextView; 
  import android.view.View.OnClickListener;
  
  public class MainActivity extends Activity implements OnClickListener { 
      LinearLayout popupLayout; 
      PopupWindow popupMessage; 
      Button popupButton, insidePopupButton; 
      TextView popupText;
  
      @Override 
      public void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState); 
          setContentView(R.layout.activity_main); init(); popupInit(); } 
          public void init() { popupButton = (Button) findViewById(R.id.popupbutton); 
  
          popupText = new TextView(this); 
          insidePopupButton = new Button(this); 
          popupLayout = new LinearLayout(this);
          popupLayout.setBackgroundColor(Color.parseColor("#dd000000"));
          popupLayout.setGravity(Gravity.CENTER);
  
          insidePopupButton.setText("OK"); 
          popupText.setText("This is Popup Window.press OK to dismiss it."); 
          popupText.setPadding(30, 40, 30, 20); 
          popupLayout.setOrientation(1); 
          popupLayout.addView(popupText); 
          popupLayout.addView(insidePopupButton); 
          } 
          public void popupInit() { 
              popupButton.setOnClickListener(this); 
              insidePopupButton.setOnClickListener(this); 
              popupMessage = new PopupWindow(popupLayout, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
              popupMessage.setContentView(popupLayout);
              popupMessage.showAtLocation(this, Gravity.CENTER, 0, 0);
  
  
          } 
          @Override public void onClick(View v) { 
              if (v.getId() == R.id.popupbutton) { 
                  popupMessage.showAsDropDown(popupButton, 0, 0); 
                  } 
              else { 
                  popupMessage.dismiss(); 
                  } } }
  </code></pre>
  
  <p>Below is the the xml layout code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" &gt;
   &lt;TextView android:id="@+id/text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="56dp" 
       android:text="good day, click button below to see popup" /&gt;
  
       &lt;Button
           android:id="@+id/popupbutton"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_centerHorizontal="true"
           android:text="Show Popup" /&gt;
  
        &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>updated code</p>
  
  <pre><code>/**
   * Copyright 2010-present Facebook.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package com.facebook.samples.friendpicker;
  
  import android.app.Activity; 
  import android.os.Bundle; 
  import android.view.Gravity;
  import android.view.View; 
  import android.view.View.OnClickListener; 
  import android.view.ViewGroup.LayoutParams; 
  import android.widget.Button; 
  import android.widget.LinearLayout; 
  import android.widget.PopupWindow; 
  import android.widget.TextView; 
  
  public class PopupDemoActivity extends Activity implements OnClickListener { 
      LinearLayout layoutOfPopup; 
      PopupWindow popupMessage; 
      Button popupButton, insidePopupButton; 
      TextView popupText;
  
      @Override 
      public void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState); 
          setContentView(R.layout.main); init(); popupInit(); } 
          public void init() { popupButton = (Button) findViewById(R.id.popupbutton); 
          popupText = new TextView(this); 
          insidePopupButton = new Button(this); 
          layoutOfPopup = new LinearLayout(this); 
          insidePopupButton.setText("OK"); 
          popupText.setText("This is Popup Window.press OK to dismiss it."); 
          popupText.setPadding(0, 0, 0, 20); 
          layoutOfPopup.setOrientation(1); 
          layoutOfPopup.addView(popupText); 
          layoutOfPopup.addView(insidePopupButton); 
          } 
          public void popupInit() { 
              popupButton.setOnClickListener(this); 
              insidePopupButton.setOnClickListener(this); 
              View parent = findViewById(R.layout.main);
              popupMessage = new PopupWindow(layoutOfPopup, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
              popupMessage.setContentView(layoutOfPopup);
              popupMessage.showAtLocation(parent, Gravity.CENTER, 0, 0);
          } 
          @Override public void onClick(View v) { 
              if (v.getId() == R.id.popupbutton) { 
                  popupMessage.showAsDropDown(popupButton, 0, 0); 
  
                  } 
              else { 
                  popupMessage.dismiss(); 
                  } } }
  </code></pre>
  
  <p>message from logcat</p>
  
  <pre><code>07-29 12:36:19.761: E/AndroidRuntime(1720): FATAL EXCEPTION: main
  07-29 12:36:19.761: E/AndroidRuntime(1720): Process: com.example.popuptest, PID: 1720
  07-29 12:36:19.761: E/AndroidRuntime(1720): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.popuptest/com.example.popuptest.PopupDemoActivity}: java.lang.NullPointerException
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.os.Handler.dispatchMessage(Handler.java:102)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.os.Looper.loop(Looper.java:136)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.ActivityThread.main(ActivityThread.java:5017)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at java.lang.reflect.Method.invoke(Method.java:515)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at dalvik.system.NativeStart.main(Native Method)
  07-29 12:36:19.761: E/AndroidRuntime(1720): Caused by: java.lang.NullPointerException
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:814)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at com.example.popuptest.PopupDemoActivity.popupInit(PopupDemoActivity.java:41)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at com.example.popuptest.PopupDemoActivity.onCreate(PopupDemoActivity.java:23)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.Activity.performCreate(Activity.java:5231)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  07-29 12:36:19.761: E/AndroidRuntime(1720):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  </code></pre>