安卓布局 - 填充剩余空间除了

29

我有一个相对布局。为简单起见,其中有一个 ImageViewEditText 和一个 Button

  • ImageView 是一个固定高度的横幅
  • 在其下方是一个 EditText,其中 android:layout_width="fill_parent"
  • 在其下方是一个具有固定宽度和高度的 Button

问题是我想让 editText 填充屏幕的剩余高度,将图像放置在顶部,按钮放置在底部,在中间放置一个填满其余空间的编辑文本框。

我需要使用哪个属性才能获得类似于这样的效果?


3
小细节: "fill_parent"已经被弃用,请使用"match_parent"代替。请参见http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT - Tim Kist
2个回答

68
为此,可以使用具有layout_weight属性的LinearLayout。使用LinearLayout来容纳这三个元素。对于ButtonImageView,将layout_height设置为wrap_content。对于EditText,将layout_height="0dp"layout_weight="1"设置。

3

您考虑使用相对布局了吗?

您可以使用


android:layout_below<br>
android:layout_alignParentTop<br>
android:layout_alignParentBottom<br>
android:layout_marginTop<br>
android:layout_marginBottom<br>

如果你遇到困难,请尝试并发布一些示例代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接