I am using PhotoView to implement Pinch to Zoom feature. Fortunately enough, my app is able to fetch the picture from the given uri, but when it comes to display it, it only shows a transparent box.
image_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/zoom_iv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Kotlin code to achieve the functionality:
...
binding.image.setOnClickListener(){
ImageLayoutDialog()
}
...
...
...
private fun ImageLayoutDialog() {
val imageLayoutBinding =
ImageLayoutBinding.inflate(LayoutInflater.from(requireContext()))
val photoView: PhotoView = imageDialogBinding.zoomIv
val mBuilder = AlertDialog.Builder(requireContext())
.setView(
imageLayoutBinding .root
)
Glide.with(requireActivity())
.load(customUri)
.into(photoView)
val mAlertDialog : AlertDialog = mBuilder.create()
mAlertDialog.show()
mAlertDialog.setCanceledOnTouchOutside(false)
}
When I click on image I get a transparent screen. But I am expecting the contents of customUri there. Any solution to this?
EDIT 1.0
Now the dialog box loads up. But it doesn't shows the image, after setting the view.
In this case I would recommend you to use other type of Dialogs. Like a DialogFragment, or an AppCompatDialog.
Solution using an AppCompatDialog (which I think will be the most similar to your need):
}
Instantiating the AppCompatDialog:
I know is not an alert dialog, but I am trying to find a solution :D
You can always add personalized buttons to that dialog to dismiss it once its clicked with a imageDialog.cancel(), or you can also pass a lambda if you want to execute some logic in the view once its clicked.