我正在尝试建立视图的组合。他们必须不断地在顶部有一个Button和Edittext框,它们水平相邻,下方有一个Textviews的垂直列表。垂直列表应包含在ScrollView中,以允许用户向下滚动TextViews(发生这种情况时,顶部的Button和EditText应该仍然可见)。
protected void initLayout() {
// Declaring the vertical layout
verticalLayout=new LinearLayout(this);
verticalLayout.setOrientation(LinearLayout.VERTICAL);
//Declaring the horizontal layout
horizontalLayout=new LinearLayout(this);
horizontalLayout.setOrientation(LinearLayout.HORIZONTAL);
//set the main view as horizontal at the top
setContentView(horizontalLayout);
//Declaring the scroll view
ScrollView scrollView= new ScrollView(this);
scrollView.addView(verticalLayout);
//set the scroll view
setContentView(scrollView);
//declare and add button to horizontal view
theButton= new Button(this);
theButton.setText("Add Joke");
horizontalLayout.addView(theButton);
//declare and add edittext to horizontal view
theEditText= new EditText(this);
theEditText.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
horizontalLayout.addView(theEditText);
}
我相信我的 setContentView 可能会出错,但我不确定。