【问题标题】:Eclipse shows different then when I debug on my phone当我在手机上调试时,Eclipse 显示不同
【发布时间】:2012-06-01 20:24:54
【问题描述】:

这是 Eclipse 在编辑器中显示给我的。

http://i.stack.imgur.com/tjwu9.png

这是我在手机上运行时的样子。

http://i.stack.imgur.com/V6NG5.png

这是我正在使用的代码。

   <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom" >

    <Button
        android:id="@+id/buttonLocation"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/settings_button"

        android:text="Settings" android:textStyle="bold" android:textSize="24dp"  android:textColor="#000000" android:gravity="center_horizontal"/>
</LinearLayout>

我需要设置在中心。我该如何解决这个问题?

【问题讨论】:

    标签: android xml eclipse debugging sdk


    【解决方案1】:

    试试这个

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="bottom" >
    
        <Button
            android:id="@+id/buttonLocation"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/settings_button"
            android:gravity="center"
            android:text="Settings" android:textStyle="bold" android:textSize="24dp"  android:textColor="#000000" android:gravity="center_horizontal"/>
    </LinearLayout>
    

    【讨论】:

    • 这毫无意义。发布您的整个布局。
    【解决方案2】:

    android:layout_gravity 用于设置 View 或 Layout 相对于其父级的重力。

    为按钮元素添加 android:layout_gravity="center" 这应该使它居中。

    另外,不确定,但由于选择的文本大小,您可能会得到不同的结果...尝试更小/更大的大小并检查结果是否不同。

    【讨论】:

    • 我添加了 android:layout_gravity="center" 并更改了字体,但它仍然没有在我的手机上居中。
    • 好的,抱歉。在您的线性布局中,而不是 android:gravity="bottom" 使其成为 center
    • 我试过了,但“设置”文本仍然不在中心。我也使用了 android:gravity="bottom" 因为我想要屏幕底部的底部。文本在图形布局中居中,但当我在手机上运行时,它在左侧。
    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多