2010-08-18 69 views
2

我的項目工作正常,突然我的按鈕上的文字被垂直顯示。我指的是代替map_infobutton顯示按鈕文字垂直顯示

Info 

它被顯示

I 
n 

與F和O以外的按鍵的界限,即使我在含有TableLayout的指定高度= WRAP_CONTENT鈕釦。

它在佈局選項卡顯示在精蝕,和只出現在仿真器(沒試過在目標硬件)

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> 

任何想法?此外,如果您對我如何創建佈局有任何意見,因爲我是新手,看起來有很多選項可用,但我正在儘可能簡化它。

+0

您的佈局不會做你所描述的運行2.2我的摩托羅拉Droid什麼,我的動車組運行2.1。新版本可能沒有正確安裝在emu上。嘗試一個項目乾淨和重新部署,如果這不起作用重新創建em圖像。 – Qberticus 2010-08-18 18:24:45

回答

1

我有類似的問題。

我看到你有多個按鈕,你想要有相同的寬度,所以你指定按鈕的寬度爲「0px」,權重爲「1」。這正是我所做的。

當我在XML文件中設置按鈕文本時,事情看起來很好。但是,我有一個按鈕,根據進程是否正在運行,更改爲文本。在我的情況下,它類似於按鈕從「開始...」切換到「停止...」的情況。文本更改後,它會垂直打印,並且只顯示每個按鈕的頂部一個或兩個字母。

在閱讀您的文章後,我想到,也許文本是在確定按鈕寬度之前設置的,然後一旦按鈕寬度根據「重量」改變就不會更新。

我修改了它,使得每個按鈕,它現在讀取:

android:layout_width="fill_parent",而不是「0像素」

從理論上講,這應該有同樣的效果。但是,實際上,在更新文本之前調整按鈕寬度。行爲現在是正確的。

羅布

+0

我認爲你是對的,但你所做的改變並不奏效。我會繼續努力,謝謝 – FrinkTheBrave 2011-04-06 11:42:20