applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
17 stars 6 forks source link

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

Closed alpesh12345 closed 3 years ago

alpesh12345 commented 3 years ago

Describe the query

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 and setWidth​(int width) takes width in px.

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

Create the query with harmonyos tag in stackoverflow and share the link here:

**** https://stackoverflow.com/questions/68587533/how-much-1px-is-with-respect-to-fp-in-harmony-os

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.501 SDK API version: 5 SDK version: 2.1.1.21 Device: Not required Device OS version: Not required

Regards, Alpesh

samuel-abhishek commented 3 years ago

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

AttrHelper.fp2px()

For more details, pls kindly refer to this Docs.