Skip to content
Advertisement

How much 1px is with respect to fp in Harmony OS?

Can anyone tell px:fp ratio or code to convert fp to px.
I am building a HarmonyOS application and I want to set the width of a component to 20fp but setWidth​(int width) takes width in px.

Button button = new Button(getContext());
button.setWidth(width);

Advertisement

Answer

HarmonyOS provides the AttrHelper tool class to implement conversion between fp and px.

AttrHelper.fp2px()

For more details, pls kindly refer to this Docs.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement