I'm working on this app:
It gets a speed update every second. When speed is 120 km/h
I want the happy face (an ImageView
) to be on the top, and when speed is -120 km/h
, it should be on the bottom. 0 km/h
would be the center and so on for every speed.
I calculated a relation betweeen km/h and pixels and move the face like this:
float pxSpeedFloat = -4.375 * speed + 115;
faceImageView.setY( -pxSpeedFloat);
setY(115)
is the center of the bar, this equation works fine on Xperia Z1.
The problem is that it just work for this screen resolution, it doesn't fit other phones.
According to documentation, setY
just admits value in pixels, not in % of the screen.
How do I solve it?