【发布时间】:2011-01-23 22:33:48
【问题描述】:
好吧,这个特定的布局让我很烦。并且似乎无法找到一种方法来拥有一个 listView,底部有一排按钮,以便 listview 不会延伸到按钮的顶部,因此按钮总是捕捉到屏幕的底部。这就是我想要的:
删除了无效的 ImageShack 链接
看起来应该很容易,但我尝试过的一切都失败了。有什么帮助吗?
这是我当前的代码:
RelativeLayout container = new RelativeLayout(this);
container.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//** Add LinearLayout with button(s)
LinearLayout buttons = new LinearLayout(this);
RelativeLayout.LayoutParams bottomNavParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
bottomNavParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
bottomNavParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
buttons.setLayoutParams(bottomNavParams);
ImageButton newLayer = new ImageButton(this);
newLayer.setImageResource(R.drawable.newlayer);
newLayer.setLayoutParams(new LinearLayout.LayoutParams(45, LayoutParams.FILL_PARENT));
buttons.addView(newLayer);
container.addView(buttons);
//** Add ListView
layerview = new ListView(this);
RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
listParams.addRule(RelativeLayout.ABOVE, buttons.getId());
layerview.setLayoutParams(listParams);
container.addView(layerview);
【问题讨论】:
-
问得好,很多开发者都会卡在这个问题上。
-
谢天谢地,Android 中的设计师其实很可爱。因此,在创建布局/UI 时,请尝试使用 Designer/XML。特别是对于这种情况,因为它只是一组按钮和一个 ListView。
标签: java android listview layout