position - Android align button programmatically -
I have an Android button on a relative layout that I want to live. Animation is currently done with an object animator to move up and down the button 50 DP on a scroll event
button position currently
height = context Programs are calculated with .getResources (). GetDisplayMetrics () HeightPixels y = height - buttonheight - bottomMargin
My problem with this is that calculations work fine in picture mode, but as soon as I switch to landscape mode, The distance between is greater than portrait mode.
What did I remember?
Try to convert DP to pix
by inserting your button on the layout First:
Public static float convert pixdodp (int px, context reference) {last float scale = reference.getracecence (). GetDisplayMetrics () Density; Float dp = (float) ((px - 0.5 f) / scale); Return DP; }
This should work!
Comments
Post a Comment