所以我试图获得视图的组合建立。他们必须不断地有按钮和EDITTEXT箱体顶部水平彼此相邻并低于的一个垂直列表Textviews。垂直列表应包含在一个滚动型允许用户向下穿过TextViews滚动(该按钮和的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,但不完全确定。如果有人有任何意见,将不胜感激
欢迎来到SO。你的代码出了什么问题?你得到的结果是什么,对于预期的结果有多不同? – dic19
谢谢。代码正在显示编辑文本,但按钮和编辑文本并未显示。预期的结果是edittext和按钮位于顶部并停留在那里,因为用户滚动文本浏览 – algorhythm