I'm creating popup window open at the bottom of screen on button click event.The popup window is correctly open at the location of bottom in screen size of 720 x 1280 pixels (~294 ppi pixel density) but same as to run in the screen size of 480 x 854 pixels (~196 ppi pixel density) it is displaying in the center of screen. How to fix this popup window issue for multiple screen size.
This is my popup xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:background="@android:color/transparent"
android:orientation="vertical"
android:padding="3dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:background="@android:color/transparent"
android:orientation="vertical">
<TextView
android:id="@+id/Title"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:background="@drawable/curve_shap"
android:gravity="center_horizontal|center_vertical"
android:text="Take Photo"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/darker_gray"
android:textSize="14sp" />
<Button
android:id="@+id/button_Camera"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:background="@drawable/curve_shap"
android:text="Camera"
android:textColor="#3A86CF" />
<Button
android:id="@+id/button_Gallery"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:background="@drawable/curve_shap"
android:text="Gallery"
android:textColor="#3A86CF" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_marginTop="4dp"
>
<Button
android:id="@+id/btnCancelCamera"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/curve_shap"
android:text="Cancel"
android:textColor="#3A86CF"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
This is my popup window code.
imgProfilePic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.camera_popup, (ViewGroup) findViewById(R.id.popup_element));
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(720);
popupWindow.setHeight(350);
popupWindow.setFocusable(true);
popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 0); //87
popupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Button btnCamera = (Button) popupView.findViewById(R.id.button_Camera);
Button btnGallery = (Button) popupView.findViewById(R.id.button_Gallery);
Button btnDismiss = (Button) popupView.findViewById(R.id.btnCancelCamera);
btnCamera.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String picformat = "IMG_" + 0 + "_" + s.format(new Date()) + ".png";
Log.e(" picformat ", " = " + picformat);
Intent i = new Intent(Filter_Screen.this , Image_Cropping.class );
startActivity(i);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "classNKK_ProfilePic";
File myPath = new File(extr, picformat);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(myPath));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Log.e("Camera", " Open");
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String imageUserProfile_path = baseDir + "/classNKK_ProfilePic/" + picformat;
editor.putString("profile_picformat", imageUserProfile_path);
editor.commit();
popupWindow.dismiss();
}
});
btnGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, PROFILE_GALLERY);
Log.e("Gallery open", "");
}
});
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
}
});
And i have to create folder of layout for multiple screen size and i put the popup window xml file in this folders.
- layout
- layout-hdpi
- layout-mdpi
Thanks in advanced .