自定义的FrameLayout在TabActivity未呈现 [英] Custom FrameLayout not rendering in TabActivity

查看:151
本文介绍了自定义的FrameLayout在TabActivity未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的FrameLayout类确实在OnSizeChanged事件一些自定义图。它的完成那里而不是在OnDraw中事件,以避免重入,因此,性能的问题。这工作正常,在一个单一的应用程序的活动,但在TabActivity失败。在当前选项卡中的活动呈现正常,但在非活动标签的活动不被渲染。 这里你可以下载一个示例项目复制本。该项目是HelloTabWidget但使用HelloAndroid项目也是如此。

研究发现,onWindowVisibilityChanged事件可能帮助,但需要找到足够的尺寸绘制我的控制。在code段下面我需要一种方法在onWindowVisibilityChanged找到容器的大小。

  @覆盖
保护无效onWindowVisibilityChanged(INT可见性){
    super.onWindowVisibilityChanged(知名度);    INT宽度= this.getWidth();
    INT高度= this.getHeight();    drawContent(getCtxt(),宽度,高度);
}


解决方案

该解决方案是用OnDraw的事件做一些重构到组件,并使用一个布尔标志,以确定何时画布脏,以避免不必要的重入。 SetWillNotDraw 必须设置为false以及

I have a custom FrameLayout class which does some custom drawing on the OnSizeChanged event. It's done there and not in the OnDraw event to avoid reentrancy and therefore performance issues. This works fine in a single activity application but fails in a TabActivity. The activity in the current tab renders fine but activities in non-active tabs are not being rendered. Here you can download an example project reproducing this. The project is HelloTabWidget but uses HelloAndroid project as well.

Found that onWindowVisibilityChanged event might help but need to find adequate size to plot my control. In the code snippet below I'd need a way to find container's size at onWindowVisibilityChanged.

@Override
protected void onWindowVisibilityChanged(int visibility) {
    super.onWindowVisibilityChanged(visibility);

    int width = this.getWidth();
    int height = this.getHeight();

    drawContent(getCtxt(), width, height);
}

解决方案

The solution was using OnDraw event doing some refactoring to the component and using a boolean flag to determine when the canvas is dirty to avoid unneeded reentrancy. SetWillNotDraw had to be set to false as well.

这篇关于自定义的FrameLayout在TabActivity未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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