首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何让视图布局填充剩余空间?

如何让视图布局填充剩余空间?
EN

Stack Overflow用户
提问于 2011-06-11 22:45:56
回答 12查看 179.2K关注 0票数 207

我正在设计我的应用程序UI。我需要一个像这样的布局:

(<和>是按钮)。问题是,我不知道如何确保TextView会填满剩余的空间,因为有两个按钮的大小是固定的。

如果我使用fill_parent显示文本视图,第二个按钮(>)不能显示。

我如何制作一个看起来像图像的布局?

EN

回答 12

Stack Overflow用户

回答已采纳

发布于 2014-09-11 15:04:51

woodshy的答案对我很有效,而且它比Ungureanu Liviu的答案更简单,因为它没有使用RelativeLayout。为了清楚起见,我给出了我的布局:

代码语言:javascript
复制
<LinearLayout 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      >

     <Button
        android:layout_width = "80dp"
        android:layout_weight = "0"
        android:layout_height = "wrap_content"
        android:text="&lt;"/>
     <TextView
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        android:layout_weight = "1"/>
     <Button
        android:layout_width = "80dp"
        android:layout_weight = "0"
        android:layout_height = "wrap_content"
        android:text="&gt;"/>   
 </LinearLayout>
票数 232
EN

Stack Overflow用户

发布于 2011-06-11 22:56:36

如果<TextView>放在LinearLayout中,请将TextView<>Layout_weight属性分别设置为0和1。

如果您正在使用RelativeLayout,请将<>左右对齐,并将TextView的"Layout to left of“和"Layout to right of”属性设置为<>的ids。

票数 96
EN

Stack Overflow用户

发布于 2011-06-11 23:01:51

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

代码语言:javascript
复制
<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>
票数 72
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6316540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档