java - 非法参数异常 : Layout: -998896 < 0 in showcaseview

标签 java android showcaseview

出于某种原因,我在一些设备上遇到此错误,例如:是 google nexus 10 还是 lg g3。

这是生成此错误的代码:

mPlusButton.setClickable(false);
            guide.setVisibility(View.INVISIBLE);
            final RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            lps.setMargins(40,0,0,160);

            mViews1 = new ShowcaseView.Builder(this)
                    .setStyle(R.style.CustomShowcaseTheme3)
                    .setContentTitle("Welcome to listo")
                    .setContentText("The best way to share your to-do lists\nand manage them in just a few clicks!")
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            if(showcase_num == 0){
                                showcase_num++;
                                mViews1.setTarget(new ViewTarget(R.id.fab,MainActivity.this));
                                mViews1.setContentTitle("Manage your lists");
                                mViews1.setContentText("Press on the plus button to add a new list.\nLong press on a list to exit from it, rename, mute or delete it." +
                                        "\n\nAt both sides of the list's name you can see the number of participants and tasks on it.");
                                mViews1.setButtonText("Got it!");

                            }else{
                                mViews1.hide();
                                mViews1.destroyDrawingCache();
                                mPlusButton.setClickable(true);

                                updateList(false);

                                SharedPreferences.Editor editor = prefs.edit();
                                editor.putInt("showcase_key", 0);
                                editor.commit();
                            }

                        }
                    })
                    .doNotBlockTouches()
                    .build();

            mViews1.setButtonText("I'm ready");
            mViews1.setButtonPosition(lps);

我在互联网上没有找到任何解决方案。据我了解,出于某种原因,布局具有负值,导致 Layout.java 类抛出异常...

最佳答案

在ShowCaseView项目的github上找到了解决方案: https://github.com/amlcurran/ShowcaseView/issues/225

这是一个尚未在主分支上修复的错误,因此您需要自己编辑库。转到“TextDrawer”类并将 draw() 方法替换为:

public void draw(Canvas canvas) {
    if (shouldDrawText()) {

        float[] textPosition = getBestTextPosition();

        // ADDED FIX FOR LG G3
        // @author CollegeDev
        for (float position : textPosition) {
            if (position < 0) {
                return;
            }
        }

        if (!TextUtils.isEmpty(mTitle)) {
            canvas.save();
            if (hasRecalculated) {
                mDynamicTitleLayout = new DynamicLayout(mTitle, titlePaint,
                        (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL,
                        1.0f, 1.0f, true);
            }
            if (mDynamicTitleLayout != null) {
                canvas.translate(textPosition[0], textPosition[1]);
                mDynamicTitleLayout.draw(canvas);
                canvas.restore();
            }
        }

        if (!TextUtils.isEmpty(mDetails)) {
            canvas.save();
            if (hasRecalculated) {
                mDynamicDetailLayout = new DynamicLayout(mDetails, textPaint,
                        (int) textPosition[2],
                        Layout.Alignment.ALIGN_NORMAL,
                        1.2f, 1.0f, true);
            }
            float offsetForTitle = mDynamicTitleLayout != null ? mDynamicTitleLayout.getHeight() :
                    0;
            if (mDynamicDetailLayout != null) {
                canvas.translate(textPosition[0], textPosition[1] + offsetForTitle);
                mDynamicDetailLayout.draw(canvas);
                canvas.restore();
            }

        }
    }
    hasRecalculated = false;
}

关于java - 非法参数异常 : Layout: -998896 < 0 in showcaseview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29990497/

相关文章:

android - 使用 API8 的 getFragmentManager

android - 目标列表的 ShowcaseView ConfigOptions

android - 你如何改变 showcaseview 圆半径?

android - 将 ShowCaseView 与 ActionBarCompat/ActionBarSherlock Android 结合使用

java - 当方法名与类名相同时如何实例化嵌套类?

java - getRuntime().exec() 什么都不做

java - Android 和 java 协会

android - 通知振动,屏幕锁定时的声音

java - Hibernate 在插入之前进行选择。这是预期的行为吗?如果是,目的是什么?

java - Spring框架的目的