我正在尝试在phoneGap的根目录上设置一个简单的视图但我得到了黑屏。
这是从xml:
充气和加载的类的代码 public TopBar(Context context){
myActivity = (Activity)context;
}
protected View createTopBarView() {
RelativeLayout mainLayout = new RelativeLayout(myActivity);
mainLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
LayoutInflater inflater = myActivity.getLayoutInflater();
View layout = inflater.inflate(R.layout.top_bar, null);
topBarView = (LinearLayout) layout.findViewById(R.id.linearLayoutTopBar);
/**
* Setting Buttons....
*/
//Adding the View
mainLayout.addView(topBarView);
return mainLayout;
}
该方法返回一个视图,并在一个扩展droidGap的类中执行:
private void createLayout(){
mainRelative = new RelativeLayout(this);
mainRelative.setBackgroundResource(R.drawable.background);
View topBarView = new TopBar(this).createTopBarView();
mainRelative.setVisibility(View.VISIBLE);
mainRelative.addView(topBarView);
root.addView(mainRelative);
}
此功能是从onCreate调用的,但运行时会出现黑屏。
答案 0 :(得分:0)
您可以尝试添加
mainLayout.addView(layout);
而不是
mainLayout.addView(topBarView);
我可能会帮忙
编辑:
你有没有这样做过:setContentView(yourLayout, LayoutParams);
in onCreate?