I put a click listener in CrimeFragment as below passing the photo path to my new CrimePhotoDialogFragment:
mPhotoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPhotoFile==null || !mPhotoFile.exists()) return; //no photo
FragmentManager fm = getFragmentManager();
CrimePhotoDialogFragment dialog = CrimePhotoDialogFragment.newInstance(mPhotoFile.getPath());
dialog.show(fm, PHOTO_TAG);
}
});
The dialog fragment uses the path and tries to fill the ImageView in the layout file:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_photo, container, false);
Point size = new Point();
getActivity().getWindowManager().getDefaultDisplay().getSize(size);
Bitmap bitmap = PictureUtils.getScaledBitmap(mPath, size.x, size.y);
mPhotoView = (ImageView)v.findViewById(R.id.dialog_photo);
mPhotoView.setImageBitmap(bitmap);
return v;
}
This opens just fine, but the displayed dialog isn’t full width, has a large white bar across the top (a header?) and the photo still has dark bars (padding) on the sides. I was hoping to get a dialog where the photo filled the available space. Here’s my layout:
Any suggestions?
Finally, when I press “back” to close the dialog, I get a warning:
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
Do I need to do something to close the dialog more cleanly?
To get rid of ur padding problem, add this attribute in ur xml file
android:scaleType="fitXY"
Removing the title is easy, create the dialog using oncreateDialog, at the end dont add setTitle:)) like this code
public Dialog onCreateDialog(Bundle savedInstanceState) {
String imageFile = (String) getArguments().getSerializable(ARG_IMAGE);
View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_zoom_image, null);
Bitmap bitmap = getScaledBitmap(imageFile, getActivity());
mImageZoom = (ImageView) v.findViewById(R.id.image_zoom_view);
mImageZoom.setImageBitmap(bitmap);
**return new AlertDialog.Builder(getActivity())**
.setView(v)
.create();
Hey guys, I searched around and found a simple solution for this problem by using ThemeOverlay.AppCompat.Dialog
Simply create the Dialog with that theme and there it’ll make the dialog just as big as the image need. Here is my onCreateDialog method: