具有相同大小的两个按钮以及一个在中心拉伸时的LinearLayout文本换行问题 [英] LinearLayout text wrap problem when having two buttons of same size plus one stretched in the center

查看:121
本文介绍了具有相同大小的两个按钮以及一个在中心拉伸时的LinearLayout文本换行问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像有一个大量的关于围绕的问题,同样的大小等,但到目前为止,我,所以我不敢问也没找到确切我的情况:)

Looks like there's a plenty of questions about centering, same size etc, but so far I didn't find the exactly my case so I dare to ask :)

我需要的是三个按钮像这样的布局:

What I need is a layout of three buttons like this:

[ previous ][*select*] [  next  ]

其中 [previous] [下一页] 按钮在相同的尺寸(即在此情况下,大小 [previous] 按钮,因为它是大),并在 [*选择*] 按钮应该延伸到占据所有可用的宽度。

where [previous] and [next] buttons are of the same size (i.e. in this case, size of the [previous] button as it is bigger), and the [*select*] button should stretch to occupy all of the available width.

继的LinearLayout相同尺寸使得两个按钮的提示,我想出了下面的XML文件:

Following the hints of making two buttons in LinearLayout same sized, i came up with the following xml file:

<LinearLayout
    android:id="@+id/button_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal" >

    <Button
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="Previous" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="Select" />

    <Button
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="Next" />

</LinearLayout>

此的几乎的工程:)
除了一件事:反而让下一步按钮为 $ P $的大小相匹配pvious 按钮,Android的品牌的 previous 按钮是大小在下一步 :)
也正因为如此文本previous被包裹在两行,像

This almost works :) Except one thing: instead of making Next button to match the size of Previous button, android makes Previous button to be the size of the Next :) And because of this the text "Previous" gets wrapped in two lines, like

Previ
ous

说不上,如果这是一个错误或没有,但你可以指点我一个解决方法或一些其他方法才达到所需的布局?

Dunno if this is a bug or not, but can you advice me a workaround or some another way to achive the desired layout?

感谢您!

推荐答案

我建议使用一个RelativeLayout的

I'd suggest using a RelativeLayout

<RelativeLayout
    android:id="@+id/buttons"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    android:clickable="false">

    <Button
    android:id="@+id/previous"

    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:text="Previous" 

    android:layout_alignParentLeft="true"/>

    <Button
    android:id="@+id/next"

    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:text="Next" 

    android:layout_alignParentRight="true"/>

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Select"

    android:layout_toRightOf="@id/previous"
    android:layout_toLeftOf="@id/next" />
</RelativeLayout>

这应该工作。

这篇关于具有相同大小的两个按钮以及一个在中心拉伸时的LinearLayout文本换行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆