当文字不合适时,Android按钮被按下

时间:2012-09-17 14:52:49

标签: android layout alignment

我在屏幕底部有5个按钮(按线性布局分组,每个重量为1。在屏幕截图中,b1-b5上方的行)。但是,当文本是多行时,该特定按钮被按下,甚至在其父项之外。每个按钮的高度是一个设定值,对所有按钮都相等。 next >按钮是正确位置的唯一按钮。在某些XML下面,但这对我来说似乎很正常:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/h"
    android:orientation="horizontal" >

    <Button                                    }
        android:layout_width="0dp"             }
        android:layout_height="@dimen/h"       }   x5
        android:layout_weight="1"/>            }
</LinearLayout>

按钮b1-b5中的LinearLayout的margin_top为10dp。

截图:

screenshot http://imageshack.us/a/img441/2878/device20120917163138.png

红线是按钮应对齐的位置。蓝线是带有两行文字的按钮,绿色带有3行。

根据屏幕截图,按钮会在它们包含的更多文本行中稍微向下推。如果按钮包含太多文本,如何阻止按下按钮?我不能使用relativelayout并让他们使用alignTop,因为我需要加权

编辑:完成(虽然缩短)XML

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="6dp"
    android:paddingRight="6dp"
    android:paddingTop="6dp">
    <LinearLayout
        android:id="@+id/panel1"
        android:layout_width="match_parent"
        android:layout_height="@dimen/h"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="@dimen/margin"
        android:layout_centerHorizontal="true">
        <Button 
            android:layout_width="0dp"      }
            android:layout_height="@dimen/h"    }x5
            android:layout_weight="1"/>     }
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@+id/text"
        android:layout_alignParentTop="true">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:background="@color/black"
            android:textColor="@color/white"
            android:text="@string/longtext">
        </TextView>
    </ScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/panel1"
        android:gravity="bottom">

        <LinearLayout
            android:id="@+id/panel2"
            android:layout_width="match_parent"
            android:layout_height="@dimen/h"
            android:orientation="horizontal">

            <Button
                android:layout_width="0dp"              }
                android:layout_height="@dimen/h"    }x5
                android:layout_weight="1"/>             }
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

在XML中

,设置此值:android:baselineAligned="false"。扼杀这与你期望的相反。