无法从片段Android上运行ShowcaseView [英] Can't run ShowcaseView from Fragment in android

查看:207
本文介绍了无法从片段Android上运行ShowcaseView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ShowcaseView的最后一个版本从这里

I use the last version of ShowcaseView from here

当我试图与演示程序和它的作品的活动使用它,但是当我试图用片段用它坠毁我的应用程序没有错误logcat中

When I tried to use it with demo app and activity it works but when I tried to use it with fragments it crashed my app with no logcat errors

     @override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);

            final ImageButton saveButton = (ImageButton) view.findViewById(R.id.button_Save);
            ViewTarget viewTarget = new ViewTarget(saveButton);

            showcaseView = new ShowcaseView.Builder(getActivity())
                    .setTarget(viewTarget)
                    .setContentTitle("Reset Button")
                    .setContentText("This will erase all the data in the table except the line that in progress")
                    .build();
        }

什么可以在这里是什么问题?

what could be the problem here?

EDIT1:

当我试图做同样的事情在我的fragmentactivity和没有工作,但是当我做了同样的事情,但花了,在fragmentactivity而不是在它的工作片段声明的看法。

when I tried to do the same thing in my fragmentactivity and didn't work, but when I did the same thing but took a view that declared in the fragmentactivity and not in the fragment it worked.

EDIT2:
我设法从logcat的错误。

I managed to get the error from the logcat.

FATAL EXCEPTION: main
java.lang.IllegalArgumentException: width and height must be > 0
        at android.graphics.Bitmap.createBitmap(Bitmap.java:724)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:670)
        at com.github.amlcurran.showcaseview.ShowcaseView.updateBitmap(ShowcaseView.java:169)
        at com.github.amlcurran.showcaseview.ShowcaseView.onGlobalLayout(ShowcaseView.java:343)
        at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:839)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2050)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
        at android.view.Choreographer.doCallbacks(Choreographer.java:591)
        at android.view.Choreographer.doFrame(Choreographer.java:561)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
        at android.os.Handler.handleCallback(Handler.java:730)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5419)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
        at dalvik.system.NativeStart.main(Native Method)

我理解的错误,但的原因是什么呢?

I understand the error but what is the cause for it?

推荐答案

在我看来,最好的解决办法是将code视图的后回调中,这样一来就会被执行时,一切都渲染。

In my opinion the best solution is to place the code within the "post" callback of the view, this way it will be executed when everything is rendered.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.post(new Runnable() {
        @Override
        public void run() {
            // your showcase initialisation code here
            showcase();
        }
    });
}

我测试了它和工作就像一个魅力。

I tested it and worked like a charm.

这篇关于无法从片段Android上运行ShowcaseView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆