Closed alexeyr15 closed 9 years ago
What version of Android were you running?
I have managed to reproduce this on different Android versions (4.2, 4.4, 5.1).
Thanks, I'll take a look when I get the chance.
I wasn't able to reproduce this on my Nexus 6 running 5.1 so it may only be affecting certain screen densities. Were you running this on an emulator? What was the configuration?
I have tested on OnePlus One and emulator. Yes, it may depend on screen density because it seems FAB is shifted by 1 pixel each time after click. Check it on the emulator with low density. Also enable "Show layout bounds" in Developer options, it may help to see that FAB is shifted.
Can you post the exact emulator configuration you used? I was not able to reproduce this with the sample app on multiple devices (different screen densities and Android versions)
I use VisualStudio emulator for Android (for example, "4.7'' Lollipop (5.1.1) XHDPI Phone" configuration, but it also reproduced in the other configurations). Also it is reproduced on the real devices. I've uploaded video to demonstrate it on ZTE V815W (Android 4.4.2): http://youtu.be/WCm4X_Ddjr4
So I tried this on my Nexus 6 (5.1.1), Moto X 1st gen (4.4.2), Nexus 9 (5.1.1), and Android emulator (Nexus 4 configuration - 4.7" xhdpi running 5.1.1) and could not repro on any of them. Do you have any devices where this issue is not occurring?
I wasn't able to reproduce this on Nexus 9, OnePlus One and official Android emulator too. So it is only reproduced for me on ZTE V815W and some configurations of VisualStudio Android emulator. I've decided to investigate a bit the problem and added logging to setFabAnchor
method to watch at fab.getX()
value. After several clicks I got the next log:
08-31 22:52:32.776 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 0.0
08-31 22:52:33.585 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 368.0
08-31 22:52:39.697 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 368.0
08-31 22:52:42.891 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 367.99997
08-31 22:52:45.024 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 367.0
08-31 22:52:47.826 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 366.99997
08-31 22:52:49.637 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 366.0
08-31 22:52:51.321 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 365.99997
08-31 22:52:52.943 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 365.0
08-31 22:52:56.061 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 364.99997
08-31 22:52:58.204 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 364.0
08-31 22:52:59.888 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 363.99997
08-31 22:53:01.585 14719-14719/com.gordonwong.materialsheetfab.sample D/qweasd﹕ fab.getX() is 363.0
I don't know how but fab.getX()
is decreased gradually and FAB is shifted to the left. As a simple workaround I've added rounding for anchorX
and anchorY
:
protected void setFabAnchor(float translationX, float translationY) {
anchorX = (int) (fab.getX() + (fab.getWidth() / 2) + (translationX - fab.getTranslationX()) + 0.5f);
anchorY = (int) (fab.getY() + (fab.getHeight() / 2) + (translationY - fab.getTranslationY()) + 0.5f);
}
After that it works as it should without any shifting.
Thanks for investigating and finding a fix! I'll push a new version with it soon.
I am also facing a shift but with a single click only and that too a larger one. I have commented on other issue but since it is closed hence commenting here only. Gist - https://gist.github.com/codeismine/6e0ad2c690c37d5057e1
Please let me know if I missed something.
Android version - below 5.1 devices.
FAB is shifted to the left after many clicks on it. Steps to reproduce in the sample 1.0.3: