0

WebView 有一个非常奇怪的问题,决定询问可能遇到类似行为的经验丰富的 Android 人员。场景如下:

  • 打开一个包含一堆 textView 和单个 WebView 的活动。最初渲染一切都很好。
  • 从这个活动中打开另一个活动,显示与第一个活动相关的一些附加细节。
  • 当用户单击“返回”按钮并且详细信息活动关闭时,我希望主要活动能够正确呈现自身,但在 50% 的情况下,WebView 会立即显示,而其余活动则为黑色约一秒钟。很烦人。

我用以下代码填写活动控件:

void fillData(Context context){     

    Command cmd = cmdList.get(index);

    if(cmd.getTypeId() == CMD_TYPE_EXTENSION){
        cmdName.setText(cmd.getName());
        String extStr = DALHelper.getInstance().getExtensionName(Integer.toString(cmd.getExtensionId()));
        extName.setText(extStr.substring(0, extStr.length() - 1));
        cmdDesc.setText(cmd.getDescription());
    }else{
        String name=cmd.getName()
                .concat(" (")
                .concat(cmd.getDescription())
                .concat(")");
        cmdName.setText(name);
        cmdDesc.setText(cmd.getComments());
    }
    if(cmd.getSyntax() != null){
        String s = alignSyntaxText(cmd.getSyntax());            
        cmdSyntax.setText(s);
    }

    String params = DALHelper.getInstance().getHtmlParameters(Integer.toString(cmd.getId()));
    if(params.length() > 0){
        params = params.substring(DUMMY_TAG_INDEX);
        htmlParams.loadDataWithBaseURL("fake://not/needed", Utils.removeBadCharacters(params), "text/html", "utf-8", null);         
    }           

    scroll.fullScroll(ScrollView.FOCUS_UP);
}

最后一次调用 fullScroll() 可能是原因吗?

Something else to mention is that the WebView sits inside a scrollView along with other text fields, however it wraps content so there are no double-scrolling glitches there.

Thank You

4

1 回答 1

0

Finally the problem was found. Was caused by double call to fillData() method mentioned above, first time while opening the Details activity and the second time in onResume() of main activity. Most likely it caused some rendering glitches, not sure what exactly though.

于 2013-09-14T10:38:50.070 回答