【问题标题】:Button text appears vertical按钮文本垂直显示
【发布时间】:2011-03-31 17:12:56
【问题描述】:

我的项目工作正常,突然我的按钮上的文本被垂直显示。我的意思是不是显示 map_infobutton

Info

它正在显示

I
n

f 和 o 超出了按钮的范围,即使我在包含按钮的 TableLayout 中指定了 height=wrap_content。

在 Eclipse 的“布局”选项卡中显示正常,仅在模拟器中垂直显示(未在目标硬件上尝试)

其中一个按钮的getPaddingLeft 在代码中的不同点返回11。不知道它是从哪里得到的,但无论如何间距看起来都比那个大。我确实有三个按钮并拿走了一个,但是两个和三个按钮都存在问题。

我的布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
    android:id="@+id/map_header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:paddingTop="8px"
    android:paddingBottom="8px"
    android:gravity="center"
    android:textColor="@color/header_foreground"
    android:background="@color/header_background"
    android:text="@string/map_header"/>
  <TableLayout
    android:id="@+id/map_footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:paddingTop="4px"
    android:paddingLeft="2px"
    android:paddingRight="2px"
    android:stretchColumns="*"
    android:textColor="@color/footer_foreground"
    android:background="@color/footer_background">
    <TableRow>
      <Button
        android:id="@+id/map_infobutton"
        android:layout_width="0px"
        android:layout_weight="1"
        android:text="@string/map_infobutton" />
      <Button
        android:id="@+id/map_selectbutton"
        android:layout_width="0px"
        android:layout_weight="1"
    android:text="@string/map_selectbutton" />
</TableRow> 
  </TableLayout>
  <LinearLayout
    android:id="@+id/map_selectiondetails"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/map_footer"
    android:orientation="horizontal"
    android:gravity="center"
    android:textColor="@color/main_foreground"
    android:background="@color/main_background" >
    <TextView
        android:id="@+id/map_selectionname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="4px"
        android:textColor="@color/main_foreground"
        android:background="@color/main_background"/>
    <TextView
        android:id="@+id/map_selectiondistance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="4px"
        android:paddingRight="4px"
        android:textColor="@color/main_foreground"
        android:background="@color/main_background"/>
    <TextView
        android:id="@+id/map_selectionvar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="4px"
        android:paddingRight="4px"
        android:textColor="@color/main_foreground"
        android:background="@color/main_background"/>
    <TextView
        android:id="@+id/map_selectionvar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="4px"
        android:paddingRight="4px"
        android:textColor="@color/main_foreground"
        android:background="@color/main_background"/>
    <TextView
        android:id="@+id/map_selectionvar3"
    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="4px"
        android:textColor="@color/main_foreground"
        android:background="@color/main_background"/>
      </LinearLayout>
      <SurfaceView
        android:id="@+id/map_map"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_above="@id/map_selectiondetails"
        android:layout_below="@id/map_header"
        android:clickable="true"/>

    </RelativeLayout>

有什么想法吗?另外,如果您对我如何创建布局有任何意见,因为我是新手,而且似乎有很多可用选项,但我正在努力使其尽可能简单。

【问题讨论】:

  • 您的布局与您在运行 2.2 的摩托罗拉机器人和运行 2.1 的 emu 上描述的不符。 emu 上可能没有正确安装新版本。尝试清理并重新部署一个项目,如果这不起作用,则重新创建 emu 映像。

标签: android


【解决方案1】:

我也遇到过类似的问题。

我看到您有多个按钮希望具有相同的宽度,因此您将按钮的宽度指定为“0px”,将权重指定为“1”。这正是我所做的。

当我在 XML 文件中设置按钮文本时,一切看起来都很好。但是,我有一个按钮可以更改文本,具体取决于进程是否正在运行。就我而言,这类似于按钮从“开始...”切换到“停止...”的情况。文本更改后,它会垂直打印,并且只显示每个按钮的顶部一两个字母。

看了你的帖子后,我突然想到,也许是在确定按钮宽度之前设置了文本,一旦按钮宽度根据“重量”发生变化,就不会更新。

我对其进行了修改,使得在每个按钮中,它现在显示为:

android:layout_width="fill_parent" 而不是“0px”

理论上,这应该具有相同的效果。但是,在实践中,按钮宽度会在文本更新之前进行调整。现在行为是正确的。

罗伯

【讨论】:

  • 我认为您是对的,但是您显示的更改无效。不过,我会继续尝试,谢谢
猜你喜欢
  • 2012-02-25
  • 2021-04-13
  • 2013-03-07
  • 2012-01-05
  • 1970-01-01
  • 2013-06-04
  • 1970-01-01
  • 2011-12-16
  • 2019-11-18
相关资源
最近更新 更多