-
Notifications
You must be signed in to change notification settings - Fork 298
Open
Description
主线程更新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);
}Metadata
Metadata
Assignees
Labels
No labels