如何使视图布局填补剩余空间?视图、布局、剩余、空间

2023-09-12 10:52:12 作者:偷走你满眼温柔

我设计我的应用程序的用户界面。我需要一个布局是这样的:

I'm designing my application UI. I need a layout looks like this:

(小于和>按钮)。问题是,我不知道如何来确保的TextView将填补剩余的空间,有两个按钮具有固定大小。

(< and > are Buttons). The problem is, I don't know how to make sure the TextView will fill the remaining space, with two buttons have fixed size.

如果我用FILL_PARENT的文本视图,无法显示在第二个按钮(>)。

If I use fill_parent for Text View, the second button (>) can't be shown.

感谢您的阅读。

推荐答案

如果你使用RelativeLayout的,你可以做这样的事情:

if you use RelativeLayout, you can do it something like this:

<RelativeLayout
 android:layout_width = "fill_parent"
 android:layout_height = "fill_parent">
 <ImageView
  android:id = "@+id/my_image"
  android:layout_width = "wrap_content"
  android:layout_height = "wrap_content"
  android:layout_alignParentTop ="true" />
 <RelativeLayout
  android:id="@+id/layout_bottom"
  android:layout_width="fill_parent"
  android:layout_height = "50dp"
  android:layout_alignParentBottom = "true">
   <Button
     android:id = "@+id/but_left"
     android:layout_width = "80dp"
     android:layout_height = "wrap_content"
     android:text="&lt;"
     android:layout_alignParentLeft = "true"/>
    <TextView
     android:layout_width = "fill_parent"
     android:layout_height = "wrap_content"
     android:layout_toLeftOf = "@+id/but_right"
     android:layout_toRightOf = "@id/but_left" />
    <Button
     android:id = "@id/but_right"
     android:layout_width = "80dp"
     android:layout_height = "wrap_content"
     android:text="&gt;"
     android:layout_alignParentRight = "true"/>
  </RelativeLayout>
</RelativeLayout>