DUICUO

HarmonyOS オープンソースのサードパーティコンポーネント - BoomMenu フローティングボタンポップアップメニューコンポーネント

[[415608]]

詳細については、以下をご覧ください。

51CTOとHuaweiが共同で構築したHarmonyOSテクノロジーコミュニティ。

https://harmonyos..com

序文

AndroidプラットフォームをベースとしたフローティングボタンポップアップメニューコンポーネントであるBoomMenu(https://github.com/Nightonke/BoomMenu)は、HarmonyOS向けの機能移行とリファクタリングを実装しています。コードはオープンソース(https://gitee.com/openneusoft/boom-menu)で公開されており、開発者の皆様はぜひダウンロードしてご利用いただき、貴重なフィードバックをお寄せください。

背景

BoomMenuは、表示される要素の数と位置をカスタマイズできる、爆発的な効果を生み出すディスプレイコンポーネントです。単独で表示することも、コンポーネントコンテナ(リストなど)に追加することもできます。BoomMenuコンポーネントは、印象的な視覚効果と多様なスタイルを誇ります。

コンポーネント効果表示

BoomMenuコンポーネントにはメインメニューページが含まれています。メインメニュー上の様々なボタンをクリックすると、異なるサブメニューページに移動します。これらのサブメニューは、画像に示すように、様々なスタイルとポップアップおよび折りたたみ効果を備えており、非常にクールな効果を生み出しています。

画像フェードビュー効果のデモンストレーション

画像: ボタン配置の配置効果のデモ

画像: カスタム位置効果のデモンストレーション

画像ドラッグ効果のデモンストレーション

画像: シンプルな円形ボタン効果のデモンストレーション

サンプル分析

最初のデモを作成する前に、いくつかのファイルを設定する必要があります。

ステップ 1.ビルド ファイルに Gradle を追加します。

  1. すべてのプロジェクト {
  2. リポジトリ {
  3. ...
  4. mavenCentral()
  5. }
  6. }

ステップ2.依存関係を追加する

  1. 依存関係 {
  2. 実装'io.openharmony.tpc.thirdlib:boommenu:1.0.0'  
  3. }

それから、コードの記述とレイアウトの作成を始めました。

ステップ 3. BoomMenuButton を XML に追加します。

  1. <com.nightonke.boommenu.BoomMenuButton
  2. ohos:id= "$+id:boom"  
  3. ohos:width= "match_content"  
  4. ohos:height= "match_content"  
  5. ohos:align_parent_bottom= "true"  
  6. ohos:align_parent_right= "true"  
  7. ohos:align_parent_end= "true"  
  8. ohos:margin= "20dp"  
  9. app:boom_inActionBar= "false"  
  10. app:boom_button_color= "$color:colorPrimary"  
  11. app:boom_button_pressed_color= "$color:colorPrimary"  
  12. />

ステップ 4. onStart() メソッドで、findComponentById を使用して BoomMenuButton を初期化します。

  1. パブリックvoid onStart(インテント インテント) {
  2. super.onStart(インテント);
  3.  
  4. コンポーネントコンテナ cc = initView();
  5. super.setUIContent(cc);
  6. LayoutScatter mInflater = LayoutScatter.getInstance(this);
  7.  
  8. コンポーネント actionBar = mInflater.parse(ResourceTable.Layout_custom_actionbar, null , true );
  9.  
  10. ブームメニューボタンの leftBmb = (ブームメニューボタン) actionBar.findComponentById(ResourceTable.Id_action_bar_left_bmb);
  11. ブームメニューボタン rightBmb = (ブームメニューボタン) actionBar.findComponentById(ResourceTable.Id_action_bar_right_bmb);
  12.  
  13. leftBmb.setButtonEnum(ButtonEnum.TextOutsideCircle);
  14. leftBmb.setPiecePlaceEnum(PiecePlaceEnum.DOT_9_1);
  15. 左Bmb.setButtonPlaceEnum(ButtonPlaceEnum.SC_9_1);
  16. for ( int i = 0; i < leftBmb.getPiecePlaceEnum().pieceNumber(); i++)
  17. leftBmb.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilderWithDifferentPieceColor());
  18. leftBmb.buildButton();
  19.  
  20. rightBmb.setButtonEnum(ButtonEnum.Ham);
  21. rightBmb.setPiecePlaceEnum(PiecePlaceEnum.HAM_4);
  22. rightBmb.setButtonPlaceEnum(ButtonPlaceEnum.HAM_4);
  23. for ( int i = 0; i < rightBmb.getPiecePlaceEnum().pieceNumber(); i++)
  24. rightBmb.addBuilder(BuilderManager.getHamButtonBuilderWithDifferentPieceColor());
  25. rightBmb.buildButton();
  26. }
  27.  
  28.  
  29. blic ComponentContainer initView(){
  30. DirectionalLayout myLayout = 新しい DirectionalLayout(this);
  31. myLayout.setWidth(MATCH_PARENT);
  32. myLayout.setHeight(MATCH_PARENT);
  33. myLayout.setOrientation(Component.VERTICAL);
  34.  
  35. ShapeElement 要素 = 新しい ShapeElement();
  36. 要素.setRgbColor(新しいRgbColor(255, 255, 255));
  37. myLayout.setBackground(要素);
  38.  
  39. myLayout.addComponent(アクションバーの取得());
  40. myLayoutを返します
  41.  
  42. }
  43.  
  44. プライベートツールバー getActionBar() {
  45. ツールバーnullの場合
  46. ツールバー = 新しいツールバー(getContext());
  47. toolBar.setLayoutConfig(新しい DirectionalLayout.LayoutConfig(MATCH_PARENT、Utils.vpToPx(getContext()、56)));
  48.  
  49.  
  50. ShapeElement 要素 = 新しい ShapeElement();
  51. 要素.setRgbColor(新しいRgbColor(63,81,180));
  52. toolBar.setBackground(要素);
  53. toolBar.setLeftImageElement(新しい VectorElement(getContext(), ResourceTable.Graphic_ic_gallery_view));
  54. toolBar.setTitleTextColor(Color.WHITE, Color.WHITE);
  55. ツールバーのタイトルを設定します(ResourceTable.String_actionBar の文字列を取得します)。
  56.  
  57.  
  58. toolBar.setMenuVisibility(Component.HIDE);
  59. toolBar.setOtherImageElement(新しい VectorElement(getContext(), ResourceTable.Graphic_ic_ellipsis_vertical_white));
  60. toolBar.setClickedListener(新しいComponent.ClickedListener() {
  61. @オーバーライド
  62. パブリックvoid onClick(コンポーネント コンポーネント) {
  63. bmb = (BoomMenuButton) リソーステーブルId_bmbからコンポーネントIDを検索します。
  64. bmb != nullをアサートします
  65. bmb.setButtonEnum(ButtonEnum.Ham);
  66. ( int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i++)の場合
  67. bmb.addBuilder(BuilderManager.getHamButtonBuilderWithDifferentPieceColor());
  68. bmb.buildButton();
  69. }
  70. });
  71. }
  72. ツールバーを返します
  73. }

やっと

最後に、BoomMenuフローティングボタンポップアップメニューコンポーネントの実装プロセスをまとめます。まず、GradleビルドファイルのXMLにBoomMenuButtonを追加し、ページレイアウトを作成し、最後にBoomMenuButtonを初期化します。

詳細については、以下をご覧ください。

51CTOとHuaweiが共同で構築したHarmonyOSテクノロジーコミュニティ。

https://harmonyos..com