我现在处于困境:我想在底部有一个滚动视图+一个固定按钮,但是编程方式!由于某些技术原因,我不能使用XML。
其实我有这个:
//Is it really usefull Relative View?
RelativeLayout layout = new RelativeLayout(this);
ScrollView sv = new ScrollView(this);
sv.setId(2);
// What is it? RelativeLayout.LayoutParams?
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, sv.getId());
sv.setLayoutParams(new ViewGroup.LayoutParams(480, 800));
layout.addView(saveButton, lp);
layout.addView(sv);
我在“固定按钮和滚动视图Android编程”中执行前3页谷歌
我在Android上初学者,所以,不要犹豫,在我的代码上发表一些暗示评论;)
感谢您的帮助。
答案 0 :(得分:2)
试试这个
LinearLayout layout = new LinearLayout(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(lp);
ScrollView scroll = new ScrollView(this);
LinearLayout.LayoutParams slp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,0, 1.0f);
scroll.setLayoutParams(slp);
Button btn = new Button(this);
ViewGroup.LayoutParams blp = new ViewGroup.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(blp);
btn.setText("Click Me");
layout.addView(scroll);
layout.addView(btn);
setContentView(layout);
答案 1 :(得分:0)
如果您尝试创建一个视图,其中屏幕的上半部分是滚动列表,而底部是一个按钮,请将scrollview放在linearlayout中,然后将该按钮放在scrollview下方的linearlayout中。 / p>
http://developer.android.com/reference/android/widget/LinearLayout.html