BoomMenu未显示

huangapple go评论79阅读模式
英文:

BoomMenu not showing

问题

我正在尝试创建一个 Boom 菜单,我的设备是 Android 10。我正在使用 BoomMenu 2.1.1 版本。以下是我的 XML 代码。问题是,当我打开活动时,出现以下错误,导致应用崩溃:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
   at java.util.ArrayList.get(ArrayList.java:437)
   at com.nightonke.boommenu.BoomMenuButton.createPieces(BoomMenuButton.java:408)
   at com.nightonke.boommenu.BoomMenuButton.doLayoutJobs(BoomMenuButton.java:390)
   at com.nightonke.boommenu.BoomMenuButton.onLayout(BoomMenuButton.java:376)
   // 其他错误信息

以下是我的当前 XML 和 Java 代码。我已经在我的活动中设置了 bmb_buttonEnumbmb_piecePlaceEnumbmb_buttonPlaceEnum(即使不设置或实例化 BoomMenuButton,仍会在打开活动时崩溃):

XML 代码:

<com.nightonke.boommenu.BoomMenuButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_margin="@dimen/fab_margin"
    android:id="@+id/bmb"
/>

Java 代码:

developer_options = (BoomMenuButton) rootView.findViewById(R.id.bmb);
developer_options.setButtonEnum(ButtonEnum.Ham);
developer_options.setPiecePlaceEnum(PiecePlaceEnum.HAM_3);
developer_options.setButtonPlaceEnum(ButtonPlaceEnum.HAM_3);

我曾尝试使用以下 XML 代码,但即使在活动端什么都不设置,仍然会导致崩溃:

<com.nightonke.boommenu.BoomMenuButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_margin="@dimen/fab_margin"
    app:bmb_buttonEnum="ham"
    app:bmb_piecePlaceEnum="piecePlace_ham_4"
    app:bmb_buttonPlaceEnum="buttonPlace_ham_4"
    android:id="@+id/bmb"
/>

请问你需要关于此问题的进一步帮助吗?

英文:

I am trying to create a boom Menu.my device is an android 10.Am using BoomMenu 2.1.1
this is my xml code .Problem is that my activity crushes when opened with the below error

 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.get(ArrayList.java:437)
    at com.nightonke.boommenu.BoomMenuButton.createPieces(BoomMenuButton.java:408)
    at com.nightonke.boommenu.BoomMenuButton.doLayoutJobs(BoomMenuButton.java:390)
    at com.nightonke.boommenu.BoomMenuButton.onLayout(BoomMenuButton.java:376)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1775)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
    at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
    at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
    at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
    at com.android.internal.policy.DecorView.onLayout(DecorView.java:783)
    at android.view.View.layout(View.java:22090)
    at android.view.ViewGroup.layout(ViewGroup.java:6358)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3239)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2735)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1821)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7916)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:980)
    at android.view.Choreographer.doCallbacks(Choreographer.java:804)
    at android.view.Choreographer.doFrame(Choreographer.java:739)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:264)

Below is my current xml and java code.I set bmb_buttonEnum and bmb_piecePlaceEnum and bmb_buttonPlaceEnum from my activity(Even without setting or instantiating the BoomMenuButton,still crushes on openint the activity)

 &lt;com.nightonke.boommenu.BoomMenuButton
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;bottom|end&quot;
    android:layout_alignParentBottom=&quot;true&quot;
    android:layout_alignParentRight=&quot;true&quot;
    android:layout_margin=&quot;@dimen/fab_margin&quot;
     android:id=&quot;@+id/bmb&quot;

   /&gt;

developer_options = (BoomMenuButton) rootView.findViewById(R.id.bmb);
                developer_options.setButtonEnum(ButtonEnum.Ham);
                developer_options.setPiecePlaceEnum(PiecePlaceEnum.HAM_3);
                developer_options.setButtonPlaceEnum(ButtonPlaceEnum.HAM_3);

i had tried to use the below with nothing on the activity side but stil crushes

    &lt;com.nightonke.boommenu.BoomMenuButton
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;bottom|end&quot;
    android:layout_alignParentBottom=&quot;true&quot;
    android:layout_alignParentRight=&quot;true&quot;
    android:layout_margin=&quot;@dimen/fab_margin&quot;
    app:bmb_buttonEnum=&quot;ham&quot;
    app:bmb_piecePlaceEnum=&quot;piecePlace_ham_4&quot;
    app:bmb_buttonPlaceEnum=&quot;buttonPlace_ham_4&quot;
    android:id=&quot;@+id/bmb&quot;
    /&gt;

答案1

得分: 0

在.xml或.java文件中设置button-enum, piece-place-enum和button-place-enum后,您需要为活动中的每个按钮初始化生成器。

创建一个图像数组以显示在每个boomButton上(除非您希望它们相同):

Integer[] bmbImages = {R.drawable.ic_image, R.drawable.ic_image2, R.drawable.ic_image3}

创建用于按钮内部文本的数组:

String[] bmbText = {getString(R.string.your_string), getString(R.string.text2), getString(R.string.text3)};

循环遍历每个boomButton以进行自定义:

for (int i = 0; i < developer_options.getPiecePlaceEnum().pieceNumber(); i++) {
    HamButton.Builder builder = new HamButton.Builder()
        .normalImageRes(bmbImages[i])
        .normalTextRes(bmbText[i])
        .subNormalTextRes("这里是子文本数组");

    developer_options.addBuilder(builder);
}

这是我获取这些信息的链接:
GitHub上的BoomMenu

英文:

After you set button-enum, piece-place-enum, and button-place-enum in .xml or .java, you have to initialize the builder for each button in your activity.

Create an array of images to show on each boomButton (unless you want them to be the same)

Integer[] bmbImages = {R.drawable.ic_image, R.drawable.ic_image2, R.drawable.ic_image3}

Create an array for the text inside

String[] bmbText = {getString(R.string.your_string), getString(R.string.text2), getString(R.string.text3)};

Loop through each boomButton to customize

for (int i = 0; i &lt; developer_options.getPiecePlaceEnum().pieceNumber(); i++) {
     HamButton.Builder builder = new HamButton.Builder()
        .normalImageRes(bmbImages[i])
        .normalTextRes(bmbText[i])
        .subNormalTextRes(&quot;array of subtext here&quot;);

     developer_options.addBuilder(builder);}

Here is the link where I got this information from:
BoomMenu on GitHub

huangapple
  • 本文由 发表于 2020年8月6日 17:41:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63280870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定