Android Honeycomb:偏离中心的按钮文本 - 无法居中

发布于 2024-12-26 03:42:29 字数 3412 浏览 1 评论 0原文

我在将文本集中在我正在处理的布局中的按钮上时遇到问题。请参阅下面的屏幕截图(在 Eclipse 的“图形布局”选项卡中拍摄):

Button Text Problem

我不确定是什么原因造成的这。我尝试使用按钮的单独布局属性,但这没有任何效果。以下是我的布局层次结构:

LinearLayout (orientation is "vertical")
    ...
    RelativeLayout
        Button ("MM/DD/YYYY")
        Button ("HH:MM")
        TextView ("to")
        Button ("MM/DD/YYYY")
        Button ("HH:MM")
    ...
    LinearLayout (orientation is "horizontal")
        Button ("Close"; layout_weight is "1")
        Button ("Reserve Room"; layout_weight is "1")

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="1024dp"
    android:layout_height="640dp"
    android:orientation="vertical"
    android:padding="10dp" >
    ...
    <RelativeLayout
        android:id="@+id/dateTimePickersLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/startingDateButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/mm_dd_yyyy" />

        <Button
            android:id="@+id/endingTimeButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="@string/hh_mm" />

        <Button
            android:id="@+id/endingDateButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/endingTimeButton"
            android:text="@string/mm_dd_yyyy" />

        <Button
            android:id="@+id/startingTimeButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/startingDateButton"
            android:text="@string/hh_mm" />

        <TextView
            android:id="@+id/toTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerInParent="true"
            android:text="@string/to"
            android:textSize="18dp" />
    </RelativeLayout>
    ...
    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/closeButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/close" />

        <Button
            android:id="@+id/reserveRoomButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/reserve_room" />
    </LinearLayout>
</LinearLayout>

任何人都知道可能导致此问题的原因吗?

感谢您的帮助!

I have a problem with centering text on buttons in a layout that I am working on. Please see the screenshot below (taken within eclipse's "Graphical Layout" tab):

Button Text Problem

I'm not sure what's causing this. I tried playing around with the individual layout properties of the buttons, but this has not had any effect. The following is my layout hierarchy:

LinearLayout (orientation is "vertical")
    ...
    RelativeLayout
        Button ("MM/DD/YYYY")
        Button ("HH:MM")
        TextView ("to")
        Button ("MM/DD/YYYY")
        Button ("HH:MM")
    ...
    LinearLayout (orientation is "horizontal")
        Button ("Close"; layout_weight is "1")
        Button ("Reserve Room"; layout_weight is "1")

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="1024dp"
    android:layout_height="640dp"
    android:orientation="vertical"
    android:padding="10dp" >
    ...
    <RelativeLayout
        android:id="@+id/dateTimePickersLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/startingDateButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/mm_dd_yyyy" />

        <Button
            android:id="@+id/endingTimeButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="@string/hh_mm" />

        <Button
            android:id="@+id/endingDateButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/endingTimeButton"
            android:text="@string/mm_dd_yyyy" />

        <Button
            android:id="@+id/startingTimeButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/startingDateButton"
            android:text="@string/hh_mm" />

        <TextView
            android:id="@+id/toTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerInParent="true"
            android:text="@string/to"
            android:textSize="18dp" />
    </RelativeLayout>
    ...
    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/closeButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/close" />

        <Button
            android:id="@+id/reserveRoomButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/reserve_room" />
    </LinearLayout>
</LinearLayout>

Anyone have any ideas what may be causing this?

Thank you for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初与友歌 2025-01-02 03:42:29

我最终更新了 eclipse 并解决了问题。我非常失望的是,重新启动 IDE 并没有改变任何东西,特别是因为 XML 没有给其他人带来任何问题。谢谢大家的帮助!

I ended up updating eclipse and that fixed the problem. I was extremely disappointed that restarting the IDE did not change anything, especially since the XML had not posed any problems for others. Thanks for the help, everyone!

暖树树初阳… 2025-01-02 03:42:29

确保底部按钮的宽度设置为 0dp。还要确保其父 LinearLayout 的宽度设置为 match_parent。

Make sure the width of your buttons at the bottom is set to 0dp. Also make sure that their parent LinearLayout has a width set to match_parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文