Hi guys,
After hours and hours of headache i find a solution to this Challenge, but unfortunatelly i still have a problem that i will present at the end, so lets begin:
1- Create a Layout file : “zoom_layout” containig two elements, an ImageView inside of a Linear Layout:
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”>
<ImageView android:id="@+id/zoom_image_view" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout
>
2- Create a DialogFragment where we will put the crime image: i called it ZoomDialogFragment.
i follow the same convention of using a companion object newInstance() function, and in this function i pass a photoFileName variable that contain the crime.photoFileName
class ZoomDialogFragment : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.zoom_layout, container, false) val imageView = view.findViewById(R.id.zoom_image_view) as ImageView return view } companion object { fun newInstance(photoFileName: String): ZoomDialogFragment { val frag = ZoomDialogFragment() val args = Bundle() args.putSerializable("PHOTO_URI", photoFileName) frag.arguments = args return frag } }
}
3- In CrimeFragment an ImageView Object, instanciate it in onCreate View, and in onStart() i setOnclickListener to it. in this listener i create a ZoomDialogFragment instance with the crime.photoFileName and i call i FragmentDialog.show(…) function
photoView.setOnClickListener { val zoomDialog= ZoomDialogFragment.newInstance(crime.photoFileName) zoomDialog.show(fragmentManager,null) }
4- we did not finish with ZoomDialogFragment, because we need to display the photo there:
override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.zoom_layout, container, false) val imageView = view.findViewById(R.id.zoom_image_view) as ImageView
val photoFileName = arguments?.getSerializable(“PHOTO_URI”) as String
imageView.setImageBitmap(BitmapFactory.decodeFile(requireContext().filesDir.path + “/” + photoFileName))
return view }
The final result is shown in this picture:
But as you can see, there is two white bars above and bellow the image, i wonder if there is a way to display just the image!!
Let me know if you find a solution to this