好吧,这种特定的布局让我很烦。而且似乎找不到找到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);
我认为这就是您想要的。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/testbutton" android:text="@string/hello" android:layout_alignParentBottom="true" /> <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/list" android:layout_alignParentTop="true" android:layout_above="@id/testbutton" /> </RelativeLayout>