RightMenu.gif
代码位于lib_base

1. 使用

正常编写业务界面, RightMenu的置入与移出仅需修改代码, 不需要修改任何布局

  1. 业务布局(activity_test_content.xml), 正常编写

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:app="http://schemas.android.com/apk/res-auto"
    4. xmlns:tools="http://schemas.android.com/tools"
    5. android:layout_width="match_parent"
    6. android:layout_height="match_parent">
    7. <TextView
    8. android:id="@+id/textView2"
    9. android:layout_width="wrap_content"
    10. android:layout_height="wrap_content"
    11. android:layout_marginTop="120dp"
    12. android:text="示范布局"
    13. app:layout_constraintEnd_toStartOf="@+id/guideline2"
    14. app:layout_constraintStart_toStartOf="@+id/guideline2"
    15. app:layout_constraintTop_toTopOf="parent" />
    16. <TextView
    17. android:id="@+id/textView"
    18. android:layout_width="wrap_content"
    19. android:layout_height="wrap_content"
    20. android:layout_marginTop="60dp"
    21. android:text="示范布局"
    22. app:layout_constraintEnd_toStartOf="@+id/guideline"
    23. app:layout_constraintStart_toStartOf="@+id/guideline"
    24. app:layout_constraintTop_toTopOf="parent" />
    25. <TextView
    26. android:id="@+id/textView3"
    27. android:layout_width="wrap_content"
    28. android:layout_height="wrap_content"
    29. android:layout_marginTop="180dp"
    30. android:text="示范布局"
    31. app:layout_constraintEnd_toStartOf="@+id/guideline3"
    32. app:layout_constraintStart_toStartOf="@+id/guideline3"
    33. app:layout_constraintTop_toTopOf="parent" />
    34. <androidx.constraintlayout.widget.Guideline
    35. android:id="@+id/guideline"
    36. android:layout_width="wrap_content"
    37. android:layout_height="wrap_content"
    38. android:orientation="vertical"
    39. app:layout_constraintGuide_percent="0.25" />
    40. <androidx.constraintlayout.widget.Guideline
    41. android:id="@+id/guideline2"
    42. android:layout_width="wrap_content"
    43. android:layout_height="wrap_content"
    44. android:orientation="vertical"
    45. app:layout_constraintGuide_percent="0.5" />
    46. <androidx.constraintlayout.widget.Guideline
    47. android:id="@+id/guideline3"
    48. android:layout_width="wrap_content"
    49. android:layout_height="wrap_content"
    50. android:orientation="vertical"
    51. app:layout_constraintGuide_percent="0.75" />
    52. <TextView
    53. android:id="@+id/textView4"
    54. android:layout_width="wrap_content"
    55. android:layout_height="wrap_content"
    56. android:layout_marginTop="60dp"
    57. android:text="示范布局"
    58. app:layout_constraintEnd_toStartOf="@+id/guideline2"
    59. app:layout_constraintStart_toStartOf="@+id/guideline2"
    60. app:layout_constraintTop_toBottomOf="@+id/textView3" />
    61. <TextView
    62. android:id="@+id/textView5"
    63. android:layout_width="wrap_content"
    64. android:layout_height="wrap_content"
    65. android:layout_marginTop="60dp"
    66. android:text="示范布局"
    67. app:layout_constraintEnd_toStartOf="@+id/guideline"
    68. app:layout_constraintStart_toStartOf="@+id/guideline"
    69. app:layout_constraintTop_toBottomOf="@+id/textView4" />
    70. <TextView
    71. android:id="@+id/textView6"
    72. android:layout_width="wrap_content"
    73. android:layout_height="wrap_content"
    74. android:layout_marginTop="60dp"
    75. android:text="示范布局"
    76. app:layout_constraintEnd_toStartOf="@+id/guideline2"
    77. app:layout_constraintStart_toStartOf="@+id/guideline2"
    78. app:layout_constraintTop_toBottomOf="@+id/textView5" />
    79. <TextView
    80. android:id="@+id/textView7"
    81. android:layout_width="wrap_content"
    82. android:layout_height="wrap_content"
    83. android:layout_marginTop="60dp"
    84. android:text="示范布局"
    85. app:layout_constraintEnd_toStartOf="@+id/guideline3"
    86. app:layout_constraintStart_toStartOf="@+id/guideline3"
    87. app:layout_constraintTop_toBottomOf="@+id/textView6" />
    88. <TextView
    89. android:id="@+id/textView8"
    90. android:layout_width="wrap_content"
    91. android:layout_height="wrap_content"
    92. android:layout_marginTop="60dp"
    93. android:text="示范布局"
    94. app:layout_constraintEnd_toStartOf="@+id/guideline2"
    95. app:layout_constraintStart_toStartOf="@+id/guideline2"
    96. app:layout_constraintTop_toBottomOf="@+id/textView7" />
    97. <TextView
    98. android:id="@+id/textView9"
    99. android:layout_width="wrap_content"
    100. android:layout_height="wrap_content"
    101. android:layout_marginTop="60dp"
    102. android:text="示范布局"
    103. app:layout_constraintEnd_toStartOf="@+id/guideline"
    104. app:layout_constraintStart_toStartOf="@+id/guideline"
    105. app:layout_constraintTop_toBottomOf="@+id/textView8" />
    106. </androidx.constraintlayout.widget.ConstraintLayout>
  2. 放入RightMenu

    1. public class MainActivity extends AppCompatActivity {
    2. @Override
    3. protected void onCreate(Bundle savedInstanceState) {
    4. super.onCreate(savedInstanceState);
    5. setContentView(R.layout.base_right_menu);
    6. FrameLayout base_content = findViewById(R.id.base_content);
    7. LayoutInflater.from(this).inflate(R.layout.activity_test_content, base_content, true);
    8. List<String> menus = new ArrayList<>();
    9. menus.add("激活");
    10. menus.add("删除");
    11. final RightMenuUtils menuUtils = new RightMenuUtils(this);
    12. menuUtils.setData(menus, new RightMenuAdapter.OnMenuCallback() {
    13. @Override
    14. public void onMenu(int position, String menu) {
    15. menuUtils.close();
    16. Toast.makeText(MainActivity.this, "" + menu, Toast.LENGTH_SHORT).show();
    17. }
    18. });
    19. }
    20. }