Reputation: 65
I'm sorry for posting this again, I posted a nearly identical question but maybe it's too long and I got no answer. I'll get in the point directly for this question
So I made a floating icon like Facebook's ChatHead but I have some problems with its X and Y coordinates. I need to get the phone screen's for Top, Bottom, Left and Right edges to solve the problems.
What I don't get is that what are these X and Y based on? My Note 2 screen is 1280x720 but when I move the head to the Top and Bottom edge I got these random numbers from Log:
12-28 11:41:49.471: D/COORDINATES X Y(9879): 73 -571 (Top)
12-28 11:42:05.991: D/COORDINATES X Y(9879): 23 572 (Bottom)
(There is a deviation with the value due to my code's precision which is the problem I mentioned above but it's only in the range of 1-5)
I tried to sum 2 absolute Y values but the result's nowhere near 1280 which is my screen resolution so right now I'm very confuse about this?
Hope someone can help me in this, I've spent hours searching for this but still nothing comes up
FOR MORE DETAIL: This is the code of the head: (with x=0 and y=0 it'll appear in the center of the screen)
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.x = 0;
params.y = 0;
windowManager.addView(chatHead, params);
EDIT: @Jason said I should use screen's dimension (width and height of the screen if my understanding is right). But I need X and Y for moving the head and they're not based on screen's dimension. This is the link to the full code in case anyone needs: http://www.piwai.info/chatheads-basics/
Upvotes: 4
Views: 5234
Reputation: 21
Set both gravity as well as x and y co-ordinates. Example:
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 860;
params.y = 0;
This would move the view to around top center.. depending on your screen size.
Upvotes: 2
Reputation: 31
I am having a similar problem with you. and I tested my app WindowManager.LayoutParam.x and WindowManager.LayoutParam.y. (My phone is Galaxy 4S and maximum size is 1920x1280)
I figured it out the answer.
Upvotes: 3