按钮文本显示为垂直

时间:2010-08-18 18:02:18

标签: android

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

Info

正在显示

I
n

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

在eclipse的Layout选项卡中显示正常,并且只在模拟器中显示为垂直(未在目标硬件上尝试)

其中一个按钮的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>

有什么想法吗?此外,如果你对我如何创建布局有任何意见,因为我是新手,似乎有很多选项可用,但我试图让它尽可能简单。

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题。

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

当我在XML文件中设置按钮文本时,事情看起来很好。但是,我有一个按钮,根据进程是否正在运行,更改是文本。在我的情况下,它类似于按钮从“开始...”切换到“停止...”的情况。文本更改后,它会垂直打印,只显示每个按钮的顶部一个或两个字母。

在阅读完帖子之后,我想到,也许是在确定按钮宽度之前设置了文本,然后一旦按钮宽度根据“重量”改变就不会更新。

我对其进行了修改,以便在每个按钮中显示为:

android:layout_width="fill_parent"代替“0px”

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

Rob