我正在尝试在 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 调用的,但运行时出现黑屏。