首先,让我先说我不熟悉Android APK。我的解决方案可以通过阅读在线文档来解决。我试图阅读文档并得出结论我错过了一些东西。
我的目标是获取PhoneGap应用程序的根视图并将其放在ViewGroup中,并将主要Activity设置为使用新视图组。我之所以这样,是因为我可以在网页视图之上叠加其他视图。
当我创建ViewGroup时,从活动的内容视图中删除根视图,将根视图添加到ViewGroup,然后将内容视图设置为RootView,我得到一个空白屏幕。但是,如果我将ImageView添加到视图组,则图像呈现正常。这让我相信我没有用rootview或webview做一些重要的事情。
非常感谢任何建议或指导。
代码:
活动代码:
@Override
public void onCreate(Bundle savedInstanceState) {
((ViewGroup)this.root.getParent()).removeView(this.root);
this.mainView = new MainView(this.getActivity());
this.mainView.setBackgroundColor(Color.WHITE);
this.mainView.addView(this.root);
this.setContentView(this.mainView);
}
MainView代码:
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if(this.getChildCount() == 1){
this.getChildAt(0).layout(left, top, right, bottom);
}
}
答案 0 :(得分:0)
我明白了。
使用viewgroup时,必须对添加的子项调用measure:
@Override
protected void onMeasure(int width, int height){
super.onMeasure(width,height);
if(this.getChildCount() == 1){
this.getChildAt(0).measure(width,height);
}
}