Enlarging an Imageview on click

青春壹個敷衍的年華 提交于 2019-12-05 18:30:34

Google has nicely explained How to enlarge view on a touch. You can use same technique for your image view also. Check the given link for full example code.

Assuming you have a fragment with a gridview that holds your images, just attach an onItemClickListener to them and when someone clicks the image, get the ID and pass it back to the activity which will get the image from where it is located using the id and set up a new fragment with a single ImageView; that will do it.

EDIT

After reading your question a second time, I think you might have to change the way you are doing it (up to you really)

Have two arrays to store the smaller images and the larger versions of the images respectively.

Now, use a fragment or just a regular view with a gridview in it to display all your images and then implement an a click listener to keep track of which image was clicked using the position argument.

After knowing which image was clicked, just pass back the position to the activity and use that position to load the bigger image from the second array of larger images and display it in an imageview with the preset dimensions/ width/height respectively.

This is what I think will help solve your problem.

NOTE In order to pass back the position of the clicked image, you just need an interface in a fragment if you use a fragment (then implement it in your activity), otherwise, you can just get the position from within the activity and do your next task there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!