Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子线程更新星球需要反射 #34

Open
jiarWang opened this issue Dec 8, 2020 · 0 comments
Open

子线程更新星球需要反射 #34

jiarWang opened this issue Dec 8, 2020 · 0 comments

Comments

@jiarWang
Copy link

jiarWang commented Dec 8, 2020

主线程更新TagCloudView出现较多jank,可以尝试使用单独的非主线程进行维护进行优化,但是目前的TagClouldView限制了更新线程只能在主线程

解决方案:https://github.com/misakuo/3dTagCloudAndroid/pull/33/commits

如下方法可以自定义一个线程,并在线程中维护TagCloudView

//: MyThread.java    
@Override
    public void run() {
        Looper.prepare();
        mHandler = new Handler(Looper.myLooper());

        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT, Utils.dx2dp(400),
                TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
        layoutParams.gravity = Gravity.TOP;
        layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        mWindowManager.addView(mFrameLayout = new FrameLayout(mContext),
                layoutParams
        );
        mFrameLayout.setVisibility(View.GONE);
        onViewCreated(mFrameLayout);

        Looper.loop();
    }

    private void onViewCreated(FrameLayout frameLayout) {
        frameLayout.setVisibility(View.VISIBLE);
        if (frameLayout.getChildCount() == 0){
            LayoutInflater.from(mContext.getApplicationContext())
                    .inflate(R.layout.layout_planet, frameLayout);
        }
        frameLayout.setVisibility(View.VISIBLE);
        initCloudView(frameLayout);
    }

    private void initCloudView(FrameLayout frameLayout) {
        if (frameLayout.getParent() == null ) return;
        TagCloudView tagCloudView = frameLayout.findViewById(R.id.tag_cloud);
        try {
            Field handler = tagCloudView.getClass().getDeclaredField("handler");
            handler.setAccessible(true);
            handler.set(tagCloudView, new Handler(Looper.myLooper()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        TagCloudAdapter adapter = new TagCloudAdapter();
        tagCloudView.setAdapter(adapter);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant