Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image got invisible after dragging other view #51

Closed
ghost opened this issue Jan 3, 2014 · 12 comments
Closed

Image got invisible after dragging other view #51

ghost opened this issue Jan 3, 2014 · 12 comments
Labels

Comments

@ghost
Copy link

ghost commented Jan 3, 2014

Hey Mike,
I am using your Imageview class in my project all gesture working properly but when i am trying to drag other view on image view , image view getting invisible or null ?
so do you have any solution for this ?

@MikeOrtiz
Copy link
Owner

@dharmendra2012 I could not repro your issue. I tried by setting up a RelativeLayout and placing one TouchImageView on top of a second TouchImageView. I could zoom and drag both without either disappearing.

Are you sure that the issue is only with dragging views over the TouchImageView? Could it be something else? #48 and #41 caused a similar issue where the TouchImageView would disappear. Could you test with the latest changes in the dev branch?

@Foosvald
Copy link

Hello,

First of all, thank you @MikeOrtiz for TouchImageView! I've been using it a lot.

I might have the same issue as @dharmendra2012 though, and I might know why it happens. I'm using the latest dev version: https://github.com/MikeOrtiz/TouchImageView/blob/dev/src/com/example/touch/TouchImageView.java

The problem:

I have two elements in a LinearLayout. First a TextView with

android:visibility="gone"

and under this the TouchImageView. The problem then appears when I programmatically change the visibility of the TextView from "gone" to "visible". This causes

onMeasure(int widthMeasureSpec, int heightMeasureSpec)

in TouchImageView.java to get called, but the problem is that

savePreviousImageValues()

isn't called before this, meaning

float prevActualWidth = prevMatchViewWidth * normalizedScale;
[...] 
float prevActualHeight = prevMatchViewHeight * normalizedScale; 

in fitImageToView() both become 0. Thus making the image disappear. To get it back you have to pinch zoom out all the way as mentioned in #41

On the other hand, if you rotate the phone

onConfigurationChanged(Configuration newConfig)

gets called, meaning

savePreviousImageValues()

also gets called. And then everything works. If I first rotate my phone, and then change the visibility of the TextEdit the TouchImageView doesn't disappear. But this is obviously no solution.

I'm not really sure where in TouchImageView.java we should call savePreviousImageValues(), so right now I've solved this by changing it to public and simply calling it from my Activity before I change the visibility of any of the views. But this is of course an ugly hack.

I hope this helps!

@MikeOrtiz
Copy link
Owner

@Foosvald Thank you. I will try to repro this later.

@ghost
Copy link
Author

ghost commented Feb 26, 2014

Thanks for your reply .

Thanks & Regards
Dharmendra Deshmukh

On Wed, Feb 26, 2014 at 12:56 AM, Michael Ortiz notifications@github.comwrote:

@Foosvald https://github.com/Foosvald Thank you. I will try to repro
this later.

Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-36047271
.

@MikeOrtiz
Copy link
Owner

@Foosvald I cannot repro your issue. Either way, I believe I have a fix in Commit c20a532. I call savePreviousImageValues() in fitImageToView() if the prevImageWidth or prevImageHeight are equal to 0. This should fix the problem. Please try out the latest commit to the dev branch to confirm.

@Foosvald
Copy link

@MikeOrtiz This does indeed fix the problem with the image becoming invisible. The problem now is that the image jumps around instead, since the saved previous values are a bit old...

@MikeOrtiz
Copy link
Owner

@Foosvald I could not repro your issue before. Could you paste your exact Activity and XML files (either on here or as a pastebin link), as well as your android device and os version. Thanks for your help.

@codeByAvi
Copy link

yeah i too getting the same problem @MikeOrtiz . image jumps around.

@MikeOrtiz
Copy link
Owner

@avi2108 @Foosvald I think I may have figured out what you guys are seeing. First, the image jumps around only when rotating the screen. Second, it only happens when the image is not zoomed in (ie getCurrentZoom == 1). Third, the scaleType must scale the image to be large than the view size (ie, CENTER_CROP or CENTER with a large image). Are these three things true?

The problem is that I assume that when the image is not zoomed in, it should be centered. However, this is not true when the original, unzoomed image is larger than the view. In this case, getCurrentZoom == 1 but the user can still scroll the image.

So, the image shouldn't be jumping around. Rather, on rotate (when the image is unzoomed), it should be re-centering. Is this correct?

MikeOrtiz added a commit that referenced this issue Apr 13, 2014
@MikeOrtiz
Copy link
Owner

@Foosvald @avi2108 I've committed a fix to the jumping around issue. It is commit dcdddb0. Could you test it and confirm that it works as expected?

@Foosvald
Copy link

Foosvald commented Sep 2, 2014

Hello again @MikeOrtiz

Sorry for a very late answer. But this does indeed fix the exact problem I had.

Thank you for a great project! We use it a lot in our (not-released-yet) app!

@hannesa2
Copy link
Collaborator

When it still exists, please make a new issue or better a PR how to solve. I will merge it immediate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants