0

我有一个线性布局,里面有几个按钮。按钮图像大小相同,属性相同……除了一个按钮。这一个按钮的字体较小。除了这个之外的所有按钮都按照我想要的方式完美地排列在一起。出于某种原因,字体较小的按钮在屏幕上的显示位置比其他按钮稍低。我很难想到一个按钮需要更少的空间占用额外的空间。

有人可以给我提示一下要读什么吗?

编辑

这是 main.xml (似乎 SO 过滤了其中一些,所有重要的东西都在这里......)

<ScrollView android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="300px">

    <TextView
            android:id="@+id/the_text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:typeface="monospace"
            android:textSize="9pt"
            android:background="@color/paper"
            android:paddingLeft="20dp"
            android:paddingBottom="20dp"
            android:textColor="@color/type"
            />
</ScrollView>

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <Button style="@style/ASR33_button"
            android:tag="Y"
            android:text="Y"
            />

    <Button style="@style/ASR33_button"
            android:tag="N"
            android:text="N"
            />

    <Button style="@style/ASR33_button"
            android:tag="E"
            android:text="E"
            />

    <Button style="@style/ASR33_button"
            android:tag="W"
            android:text="W"
            />

    <Button style="@style/ASR33_button"
            android:tag="S"
            android:text="S"
            />

    <Button style="@style/ASR33_button"
            android:tag="F"
            android:text="F"
            />

    <Button style="@style/ASR33_button"
            android:tag="R"
            android:text="R"
            />

    <Button style="@style/ASR33_button"
            android:tag="M"
            android:text="M"
            />

    <Button style="@style/ASR33_button"
            android:tag="T"
            android:text="T"
            />

    <Button style="@style/ASR33_button"
            android:onClick="onEnterButtonClicked"
            android:textSize="6pt"
            android:text="RE-\nTURN"
            />

    <Button style="@style/ASR33_button"
            android:tag="U"
            android:text="U"
            />
</LinearLayout>

<LinearLayout
        android:orientation="horizontal"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <TextView
            android:id="@+id/instructions"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="9pt"
            android:paddingLeft="10dp"
            android:typeface="normal"
            android:text="Commands: (Y)es, (N)o, (N)orth, (E)ast, (W)est, (S)outh, (M)ap, (ST)atus, (Fight), (R)un, (SU)icide.  All commands must be followed by RETURN."
            />

</LinearLayout>

奇怪的是倒数第二个,具有不同的 onclick 事件。该样式的字符大小为 11pt。如果我使用它(和一个 1 个字母的按钮名称,就像其他人一样)它的行为。但这不是 ASR33 的“输入”键。因此,如果我将字体大小减小到 6 pt,就会发生奇怪的事情。

风格可以在这里看到。

再次,请阅读参考资料或想法,如果我有一两个词要搜索,我可以弄清楚。很难知道你不知道的...

解析度

Anurag 说得对,请参阅下面的答案。以下是更新后的 LinearLayout 的摘录:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false">
4

1 回答 1

1

可能由于按钮的 wrap_content 属性而发生了调整大小。所以你应该做的是保持所有按钮的线性布局的固定高度,而它的 with 设置为填充父母。

在线性布局中,让单个按钮设置高度以包装内容,这将使所有按钮的高度与线性布局的高度相同,并android:adjustViewBounds="true"为小按钮设置属性。此属性将调整您的图像按钮的大小以保持纵横比。我希望这有帮助。

编辑:所以这是您的问题的解决方案,这是由于线性布局的基本对齐属性引起的。默认情况下,水平 LinearLayout 对齐其所有子控件的基线。因此,多行按钮中的第一行文本与其他按钮中的单行文本垂直对齐。在 LinearLayout 上设置 android:baselineAligned="false"。这在我的 HTC 上完美运行。

于 2012-04-07T20:36:12.457 回答