-1

I am using Custom AlertDialog.Builder to show Image from SD Card into that alert dialog.

How can I use full width and height of Screen to show dialog, here is my code:

viewHolder.imageButtonView.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View v) {

    final AlertDialog.Builder imageDialog = new AlertDialog.Builder(XRayActivity.this);

    final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);

    View layout = inflater.inflate(R.layout.image_dialog, null);                       

    ImageView image = (ImageView) layout.findViewById(R.id.imageView);

    try
    {                       
        strFileName = arrayList.get(position).getFilename().toString();

        String file = Environment.getExternalStorageDirectory().getPath() + "/Pictures/XRays/" + strFileName;
        Bitmap bm = BitmapFactory.decodeFile(file);                              
        image.setScaleType(ImageView.ScaleType.FIT_XY);

        image.setImageBitmap(bm);
    } catch (Exception e) { 
        e.printStackTrace();
    }       

       imageDialog.setTitle(strFileName);
       imageDialog.setView(layout);
       imageDialog.setPositiveButton(android.R.string.ok, new 
       DialogInterface.OnClickListener(){

    public void onClick(DialogInterface dialog, int which) {

          dialog.dismiss();
         }                    
     });     

       imageDialog.create();
       imageDialog.show();

        }
    });

image_dialog.xml:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

In xml I am using only ImageView with match_parent properties of layout_width and layout_height.

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
Sophie
  • 2,594
  • 10
  • 41
  • 75
  • set `android:scaleType="fitXY"` – M D Jul 31 '15 at 10:27
  • @MD already using : image.setScaleType(ImageView.ScaleType.FIT_XY); – Sophie Jul 31 '15 at 10:28
  • Used `RelativeLayout` and also set `android:adjustViewBounds="true"` – M D Jul 31 '15 at 10:33
  • @MD i am getting image in a full width and height of Dialog, but not getting dialog in a full width and height of Screen – Sophie Jul 31 '15 at 10:38
  • And why don't create an Separate Activity if you want full screen , and you can call this activity by startActivityForResult(intent) if you want result back to your mainactivity – Sanjeev Jul 31 '15 at 10:52
  • @Sophie I don't think that trying various attributes on image view will solve your problem , you have set your own style on dialog for making it full screen. Have a look on my answer below. – Adarsh Yadav Jul 31 '15 at 11:09
  • What difference do you see in fill screen covering dialog box and an activity? – Aawaz Gyawali Jul 31 '15 at 12:13

2 Answers2

2

You can use Dialog Fragment:

@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);

        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);


        return dialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        }
    }
savepopulation
  • 11,736
  • 4
  • 55
  • 80
0

You can use style to do that

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);

}
  • What is setStyle() method it is not recognized in android studio – Sanjeev Jul 31 '15 at 10:49
  • Thats the way how to do this when you create a custom DialogFragment. This is the function: http://developer.android.com/reference/android/app/DialogFragment.html#setStyle(int, int) – daemmie Jul 31 '15 at 11:11