Search code examples
javaandroidhuawei-mobile-serviceshuawei-developersharmonyos

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);

Solution

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

    AttrHelper.fp2px()

    For more details, pls kindly refer to this Docs.