0

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);
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • Try method `AttrHelper.fp2px`. doc: https://developer.harmonyos.com/cn/docs/documentation/doc-references/attrhelper-0000001054518726 similar question: https://stackoverflow.com/questions/68542357/what-is-the-alternative-in-harmonyos-for-typedvalue-applydimensionint-unit-flo/68555697#68555697 – android_su Jul 30 '21 at 08:18

1 Answers1

1

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

AttrHelper.fp2px()

For more details, pls kindly refer to this Docs.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108